文字列(string)をfstreamでtxtに書き込む
1357 ワード
文字列(string)をfstreamでtxtに書き込む
偶然にもfstreamを用いて文字列をtxtに書き込むと、「string」を直接書き込むのは問題ないが、string str=」stringでstrを書き込むとコンパイルエラーが発生し、最後にstr.dataで文字列を書き込むことに成功した.
コードブロック
コード:
偶然にもfstreamを用いて文字列をtxtに書き込むと、「string」を直接書き込むのは問題ないが、string str=」stringでstrを書き込むとコンパイルエラーが発生し、最後にstr.dataで文字列を書き込むことに成功した.
コードブロック
コード:
#include
#include
#include
using namespace std;
int main()
{
int a=0, b=6; static string Str="abcdefg";
fstream fout("C://Users//lvyan//Desktop//testfile123.txt",ios::out); // data.txt
fout << a ; //
fout<< Str.data();
fout<< b ;
fout.close(); //
//system("pause");
return 0;
}