私は現在、.txt ファイルの内容を文字列として書き換える小さなプログラムをここに持っています。
ただし、ファイルのすべての内容を単一の文字列として収集したいのですが、どうすればよいですか?
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main () {
string file_name ;
while (1 == 1){
cout << "Input the directory or name of the file you would like to alter:" << endl;
cin >> file_name ;
ofstream myfile ( file_name.c_str() );
if (myfile.is_open())
{
myfile << "123abc";
myfile.close();
}
else cout << "Unable to open file" << endl;
}
}