get and getline in c++ code example
Example 1: getline cpp
//getline allows for multi word input including spaces ex. "Jim Barens"
#include <iostream>
#include <string>
int main()
{
string namePerson{}; // creating string
getline(cin, namePerson);// using getline for user input
std::cout << namePerson; // output string namePerson
}
Example 2: getline of file C++
ifstream inFile;
string name;
int age;
inFile.open("file.txt");
getline(inFile, name);
inFile >> age;
cout << name << endl;
cout << age << endl;
inFile.close();