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; } Quote 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. Quote 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.) Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.