程序說明: 從「names.txt」中以「First Last」格式讀取名稱列表。 根據姓氏和名字,根據人名的典型字母順序對姓名進行排序。 以「Last,First」格式將排序後的列表寫入名爲「sortednames.txt」的文件中。C++程序的排序名稱
這裏是我的代碼:文件數據存儲在全名數組中,但現在我被卡在如何翻轉數組中的姓和名?
int main()
{
const int MAXNAMES = 100;
int value = 0;
string fullname[MAXNAMES];
ifstream inFile;
inFile.open("names.txt"); //open the file to excess the rainfall data
if (inFile.fail()) // testing the file
{
cout << "Error opening file. Please check that the file currently `enter code here`exist" << endl;
exit(1);
}
cout << "File successfully open" << endl;
while(!inFile.eof())
{
while(value < 100)
{
getline(inFile,fullname[value]);
value++;
}
}
return 0;
}
確切位置在哪裏,你卡住了?你有沒有試過在僞代碼中寫下所需的步驟? –