未分類

c++ で文字列をファイルに保存する方法

投稿日:

result.txt というファイルに “data1 data2 data3” という内容を保存する。ofstream を使って書き出す。

#include<iostream>
#include<fstream>

using namespace std;

int main()
{
ofstream datafile;
datafile.open("result.txt");
datafile << "data1 data2 data3\n";
datafile.close();

return 0;
}

結果

result.txt

data1 data2 data3

-未分類

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

tex で累乗根を入力する方法

$\sqrt[n]{2}$のようにする。 例 $\sqrt[n]{2}$ 結果

no image

c++ で文字列が他の文字列を含むか判定する方法

文字列を含むかどうか判定するには、string の find を使う。見つからなかった場合は、std::string::npos を返す。 例 #include <iostream> #i …

no image

tex で小文字のL(リットル)記号を入力する方法

tex で小文字のL(l)リットル記号を入力するには、\ell を使う。通常の小文字の l は、\\l であるのに注意。 例 5 \\ell 結果

no image

tex の分数のシグマ記号(和)がつぶれないようにする

分子・分母にシグマ記号(和記号)を使うと、小さくつぶれて見にくいことがある。対策として、\displaystyle を使う。 例 $\frac{\displaystyle \sum_{i=1}^{\i …

no image

python で文字列の長さを表示する方法

len を使う。 例 length = len(‘文字列あいうえお’) print(str(length)) 結果 8