未分類

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

python3 で辞書(dict) の for ループでキーと値を取得する

キーと値を取得するには次のようにする。キーは dict のループ、値は dict の values() のループで取得できる。 例 mydictionary = {‘color’: ‘白’, ‘ani …

no image

tex で期待値記号を入力する方法

\mathbf を使う。 例 $\mathbf{E}(\xi)$ 結果

no image

python3 でクラスの初期化を __init__ で行う

python でクラスのオブジェクトを生成したとき、__init__ メソッドが呼び出される(コンストラクタ)__init__ の引数には自身(self)を指定することが通例。一方、オブジェクト破棄の …

no image

tex で行内を結合する方法

\multicolumn を使って、結合する行の成分の数を指定することができる。次の例では「3」を指定して、結合している。 例 \begin{table} \begin{tabular}{ |c|c| …

no image

tex で文章を右寄せにする方法

テキストを \flushright で囲めば良い。 例 \begin{flushright} Lorem, ipsum dolor sit amet consectetur adipisicing e …