- ベストアンサー
※ ChatGPTを利用し、要約された質問です(原文:Sortプログラムについて2)
一つのファイルを使ってソートする方法は?
このQ&Aのポイント
- 二つのファイルを使ってソートするプログラムについて質問させていただいたのですが、一つのファイルだけを使ってソートして上書きするためにはどうすればいいでしょうか?
- ソースコードを貼っておきます。
- #include <iostream> #include <fstream> #include <list> #include <string> using namespace std; int main() { char Str[255]; list<string> str; int count = 0; ifstream in("ttest", ios::binary | ios::in); if (!in){ cout << "入力ファイルが読み込めない" << endl; exit(1); } ofstream out("out", ios::binary | ios::out); if (!out){ cout << "出力ファイルが読み込めない" << endl; exit(1); } while (!in.eof()){ //!!!! in.getline(Str,255); str.push_back(Str); count++; } str.sort(); list<string>::iterator p; p = str.begin(); while(p!=str.end()){ out << *p << endl; p++; } in.close(); out.close(); getchar(); return 0; }
- みんなの回答 (1)
- 専門家の回答
お礼
できました!! 回答ありがとうございました。