
Originally Posted by
Sea Bass
Here's your code with the changes in bold:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string line;
ifstream myfile;
myfile.open("problem_1.txt");
getline (myfile,line);
getline (myfile,line);
cout << line[0] << endl;
cin.ignore();
myfile.close();
system("PAUSE");
return 0;
}
The result is that it prints out a 3.
The key points are that getline gets 1 line of the file so you need to call getline 2 times to get the 2nd line. And you can index a character in a string using [], so line[0] gets the first character, line[1] gets the 2nd, etc.