【发布时间】:2017-04-21 02:54:29
【问题描述】:
您好,我一直在尝试做一个程序,编译器从 txt 文件中获取分数并按升序输出它们,但它对什么问题没有任何想法?我怎么能把它变成一个数组?
这是我正在使用的 infile.txt:
1 John Doe 23567
2 Larry Bird 21889
3 Michael Jordan 21889
4 James Bond 13890
5 Gary Smith 10987
6 GJ 9889
7 Vivien vien 8990
8 Samantha Carl 6778
9 Gary Lewes 5667
10 Sybil Saban 4677
程序:
#include <iostream>
#include <fstream>
#include <string>
using std::ifstream;
using namespace std;
int main ()
{
ifstream file_("infile.txt");
int highscore;
std::string name;
int id;
if (file_.is_open())
{
while(file_>>id >> name >> highscore)
{
std::cout<<id << " " <<name << " " <<highscore<<"";
}
file_.close();
}
system ("pause");
return 0;
}
【问题讨论】:
标签: c++ c++11 visual-c++