Skip to content

Instantly share code, notes, and snippets.

@paxswill
Created November 12, 2012 16:51
Show Gist options
  • Save paxswill/4060464 to your computer and use it in GitHub Desktop.
Save paxswill/4060464 to your computer and use it in GitHub Desktop.
How to use getline
#include <fstream>
#include <string>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
ifstream inFile("data.txt");
while(!inFile.eof()) {
string firstName, lastName, homeTown;
inFile >> firstName >> lastName;
getline(inFile, homeTown);
cout << firstName << " " << lastName << " from " << hometown;
}
inFile.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment