Reading a .txt file

i am trying to read the 2nd line of a text file while ignoring the rest of the first line. is the ignore function the proper way to do this? when i run the program it gives me no ouput.

#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;

int main()
{
string name1, name2;
string students[10];

ifstream inData;

inData.open("F:\\students.txt");

inData >> name1;
cin.ignore(100, '\n');
inData >> name2;
cout << name1 << endl;
cout << name2 << endl;



system ("pause");
return 0;
}


ignore is correct, but you're ignoring from cin, not the file
here is the code to read 2nd line of file.:-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream> 
#include <iomanip>
using namespace std;

int main()
{
string line;

ifstream myfile ("a.txt");

if(myfile.is_open())
{
	for (int lineno = 1; getline (myfile,line) && lineno < 4; lineno++)
      if (lineno == 2)//for 2nd line 
          cout << line << endl;
    myfile.close();
  }

  else cout << "Unable to open file"; 

return 0;
}
Topic archived. No new replies allowed.