How to read a string that contains spaces into char array in C++

1 Answer

0 votes
#include <iostream>
#include <fstream>

using std::cout;
using std::endl;

int main()
{
	char s[32];

	cout << "Enter a string: ";
	
	std::cin.getline(s, 31);

	cout << s << endl;

	return 0;
}

/*
run:

Enter a string: c c++ php
c c++ php

*/

 



answered Jun 19, 2018 by avibootz

Related questions

1 answer 243 views
1 answer 316 views
1 answer 433 views
1 answer 272 views
272 views asked Jun 6, 2018 by avibootz
1 answer 274 views
1 answer 753 views
...