我有一个文件,其中有一个数字,其中是后面的名称数。例如:
4
bob
jim
bar
ted
我正在尝试编写一个程序来读取这些名称。
void process_file(ifstream& in, ofstream& out)
{
string i,o;
int tmp1,sp;
char tmp2;
prompt_user(i,o);
in.open (i.c_str());
if (in.fail())
{
cout << "Error opening " << i << endl;
exit(1);
}
out.open(o.c_str());
in >> tmp1;
sp=tmp1;
do
{
in.get(tmp2);
} while (tmp2 != '\n');
in.close();
out.close();
cout<< sp;
}
到目前为止,我能够阅读第一行并将 int 分配给 sp
我需要 sp 来计算有多少个名字。我怎样才能读懂这些名字。我剩下的唯一问题是如何在忽略第一个数字的情况下获取名称。在那之前我无法实现我的循环。