Hey guys,
Can someone tell me the difference between cin.getline and getline?
I'm kinda familiar with cin.getline but not with getline....can you also tell me the exact syntax?
thanks for your help
bart
Hey guys,
Can someone tell me the difference between cin.getline and getline?
I'm kinda familiar with cin.getline but not with getline....can you also tell me the exact syntax?
thanks for your help
bart
cin.getline is a member of ostream, and you use it with C-style strings (ie. arrays of char terminated by a null character). getline is an independent function declared in <string> for use with the std::string class. You would use it like this:
The nice thing about getline is that you don't need to specify a size because std::string grows dynamically.Code:#include <iostream> #include <string> int main() { std::string name; std::cout<<"Enter your name: "; if ( std::getline ( std::cin, name ) ) std::cout<<"Hello, "<< name <<'!'<<std::endl; }
My best code is written with the delete key.
Don't you mean istream?cin.getline is a member of ostream
>Don't you mean istream?
Yes, thank you. Can you guess what my most common bug is when working with C++?
My best code is written with the delete key.