好的,即時通訊新的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無關緊要,如果它是作業:[家庭作業標籤現在正式棄用](http://meta.stackexchange.com/questions/147100/the-homework-tag-is-now-officially -deprecated) – slugster