【发布时间】:2012-10-09 22:58:26
【问题描述】:
好的,我是 C++ 新手,但我正在做很多练习。
这是我的问题,有人可以看看我的源代码,并在这里引导我朝着正确的方向前进。
这就是我想要做的。
- 程序应该能够读取带有记录的文本文件 在里面。(做到了)
- 我还想在文本文件中使用字符串搜索记录 (没做过)
- 另外,使用小数从高到低对记录进行排序 文本文件中的数字或双精度。我想使用冒泡排序 功能。
这是我的代码
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
//double gpa;
//string
int main ()
{
string line;
ifstream myfile ("testfile.txt");
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
else cout << "Unable to open file";
char c;
cout<<"\n enter a character and enter to exit: ";
cin>>c;
return 0;
}
这是一个带有记录的示例文本文件。
aRecord 90 90 90 90 22.5
bRecord 96 90 90 90 23.9
cRecord 87 90 100 100 19.9
dRecord 100 100 100 100 25.5
eRecord 67 34 78 32 45 13.5
fRecord 54 45 65 75 34 9.84
gRecord 110 75 43 65 18.56
【问题讨论】:
-
@Radu 是作业没关系:The homework tag is now officially deprecated