#include <iostream.h>
#include <stdlib.h>
#include <fstream.h>
#include <iomanip.h>
#include <string.h>
#include <conio.h>
int view(void)
{
ifstream in("NewFaculty.txt");
if(!in) {
cout << "Cannot open input file.\n";
return 1;
}
char str[255];
while(in) {
in.getline(str, 255); // delim defaults to '\n'
if(in) cout << str << endl;
}
in.close();
getch();
return 0;
}
int main()
{
view();
}
I have this code for retrieving data from text file in C++. Using this code I am getting entire file data as output, like:
name address id
xxx hyd 0001
yyy hyd 0002
But I need output like only particular line of data by accepting input from keyboard. Need output like:
name address id
xxx hyd 0001
Here my input is name
. Please anyone help in that way.