Mega Code Archive

 
Categories / C++ / File
 

Use getline() to read a string that contains spaces

#include <iostream> #include <fstream> using namespace std; int main() {    char str[80];   cout << "Enter your name: ";   cin.getline(str, 79);   cout << str << '\n';   return 0; }