Reading a string with white space in C

Status
Not open for further replies.
I know this is kind of late, but I feel obligated to share this info. To get "white space" with the rest of your string until enter is pressed you could use the following code I got from here https://www.cplusplus.com/reference/string/getline/

Example:
Code:
#include <iostream>
#include <string>

int main()
{
string path;

cout << "Enter some text with white space: ";
getline(cin,path);
cout << "You entered: " << path << endl;
}
 

That's C++ instead of plain old 'C' but as the original poster didn't specify a version of the language maybe it is applicable in this case.

Brian.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…