I'm a n00b C++ programmer, and I would like to know how to read a specific line from a text file.. For example if I have a text file containing the following lines:
1) Hello
2) HELLO
3) hEllO
How would i go about reading, let's say line 2 and printing it on the screen? This is what i have so far..
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
string sLine = "";
ifstream read;
read.open("input.txt");
// Stuck here
while(!read.eof()) {
getline(read,1);
cout << sLine;
}
// End stuck
read.close();
return 0;
}
The code in bewteen the comments section is where I'm stuck. Thanks!!