VisualC++ ファイルの読み込み
ファイルに出力した計算結果を読み込んで、物理量の計算等を行いたいとする。
その際に必要なのが、ファイルからのデータの入力である。
sample.data
スペース区切りで1行に3つずつ(x,y,z)データがある場合を想定。
13.3283 6.00577 4.49856 3.095 2.92063 5.24022 9.02886 11.7945 5.44378 ・・・ 9.62519 0.933134 2.20219
sample.data (メトロポリスの方法を用いての計算結果N=100)
VisualC++ ソース
/*
C++ ファイルの読み込み
*/
#include <fstream>
#include <iostream>
using namespace std;
int main(){
ifstream fin_t;
fin_t.open("sample.data", ios::in);
double x,y,z;
while(!fin_t.eof()){
fin_t >> x;
fin_t >> y;
fin_t >> z;
cout <<"x=" << x << " y=" << y << " z=" << z << endl;
}
}



