I know that when writing code like std::cin >> some_var; , where some_var is a string variable, only the first word that was inputted will be stored in some_var. But I do not understand why std::cout << "something here"; does not only output “something”. Am I missing something?
I know that when writing code like std::cin >> some_var; , where some_var is
Share
When reading input using
cin >> some_var, the delimiter is space by default (you can change this though), while when printing,coutprints till its find\0which is end of the string.If you want to read till it finds
\0in the input stream, then you’ve to write this:You can give any other character as delimiter as third argument of
std::getlinefunction.Note that there is a member function with same name
getlinewhich is slightly different than the one I used above which is a free standalone function.Compare:
std::istreamI used the first one.