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 246 views
1 answer 324 views
1 answer 434 views
1 answer 279 views
279 views asked Jun 6, 2018 by avibootz
1 answer 282 views
1 answer 761 views
...