0
#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();
}
我有用于从C++文本文件中检索数据的代码。使用此代码我得到整个文件数据作为输出,如:使用C++从文本文件读取特定行
name address id
xxx hyd 0001
yyy hyd 0002
但我通过接受从键盘输入需要这样的数据只有特定的线路输出。需要输出像:
name address id
xxx hyd 0001
这里我的输入是name
。请任何人以这种方式帮助。
是的,我需要修复它,但没有得到任何想法。 –
键盘输入(ID,姓名,地址,行号)是什么? – sop
使用std :: istream :: ignore,请参阅已存在的答案中的详细信息:http://stackoverflow.com/a/25012566/492336 –