【发布时间】:2014-11-07 01:20:39
【问题描述】:
我正在尝试从 .txt 文件中读取“名字姓氏”。这是我拥有的代码(它不起作用,它只复制第一个单词),它最终会弄乱我的整个程序。我怎样才能解决这个问题。拜托,只有有用的回复
#include <fstream>
#include <iostream>
using namespace std;
//Structs
struct card {
char suit[8];
char rank[6];
int cvalue;
char location;
};
struct player {
char name[100];
int total;
card hand[];
};
int main() {
player people[4];
/open player names file
ifstream fin2;
fin2.open("Players.txt");
// check if good
if (!fin2.good()) {
cout << "Error with player file!" << endl;
return 0;
} else {
int j = 0;
fin2 >> people[j].name; //prime file
while (fin2.good()) {
j++;
fin2 >> people[j].name; //copy names into people.name
}
}
}
【问题讨论】:
-
people声明在哪里? -
Players.txt 文件是什么样的?
-
我们是
people。 -
people 在 main 下被声明。不要问你自己能回答的问题