Ninjakreborn Posted January 24, 2009 Share Posted January 24, 2009 All I am wondering is why is cin cutting out my spaces. If I type "Time to die" into the command line it returns "time". If I type "Today is the time I am performing this test" it returns "Today". This is kind of strange. Any reason why spaces are being cut out..or more of it finds the first space and everything after it is removed. #include <iostream> #include <string> using namespace std; int main() { string time; cout<<"What time is it? \n"; cin>>time; cout<<"Now that you entered the time...it is \n"; cout<<time << "\n"; system("PAUSE"); return 1; } Link to comment https://forums.phpfreaks.com/topic/142210-solved-simple-question-about-string-whitespace-in-c/ Share on other sites More sharing options...
Ninjakreborn Posted January 24, 2009 Author Share Posted January 24, 2009 sin::getline helped me solve this problem. Thanks again. Link to comment https://forums.phpfreaks.com/topic/142210-solved-simple-question-about-string-whitespace-in-c/#findComment-745016 Share on other sites More sharing options...
corbin Posted January 24, 2009 Share Posted January 24, 2009 cin reads until it hits a white space. Sometimes stringstreams are used to explode a string because of that. (Keep reading until a space, so it's essentially space delimited.) Link to comment https://forums.phpfreaks.com/topic/142210-solved-simple-question-about-string-whitespace-in-c/#findComment-745019 Share on other sites More sharing options...
Ninjakreborn Posted January 24, 2009 Author Share Posted January 24, 2009 Ah that is why. Thank you yet again. Link to comment https://forums.phpfreaks.com/topic/142210-solved-simple-question-about-string-whitespace-in-c/#findComment-745029 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.