文字判定
要求 读取popu2000.txt 文档
广州 5683062
北京 1475728
上海 1416180
成都 2365320
重庆 1189279
。
。
。
然后将城市名放入结构体 city.name[10],人口数放入 city.popu
最后按人口数由大到小排序。。
不知到用哪个函数能判断名字 还是 数字啊~
[解决办法]
#include <iostream>
#include <fstream>
#include <string>
struct City
{
char name[10];
int popu;
} city[100];
int main()
{
using namespace std;
string name;
int value, index = 0;
ifstream ifs("filename.txt");
if (ifs) {
while (ifs >> name >> value) {
strcpy(city[index].name, name.c_str());
city[index++].popu = value;
}
}
}