入出力のコードを書いていたのですが、エラーがでてしまいます。
問題点を指摘してくださるとうれしいです。
コード /* * stream.cpp * * Created on: 2015/10/29 * Author: 礼央 */ #include<iostream> #include<sstream> #include<fstream> int main() { using namespace std; ostringstream strbuf; int lucky = 7; float pi = 3.14; double e = 2.71; // cout << "An in-memory stream" << endl; strbuf << "luckynumber:" << lucky << endl << "pi:" << pi << endl << "e:" << e << endl; string strval = strbuf.str(); cout << strval; ofstream outf; outf.open("mydata"); outf << strval; outf.close(); cout << "Read data from the file-watch for errors" << endl; string newstr; ifstream inf; inf.open("mydata"); if (inf) { int lucky2; inf >> newstr >> lucky2; if (lucky != lucky2) cerr << "error! wrong" << newstr << lucky2 << endl; else cout << newstr << "OK" << endl; float pi2; inf >> newstr >> pi2; if (pi2 != pi) cerr << "Error! wrong" << newstr << pi2 << endl; else cout << newstr << "OK" << endl; double e2; inf >> newstr >> e2; if (e2 != e) cerr << "ERROR:Wrong" << newstr << e2 << endl; else cout << newstr << "OK" << endl; inf.close(); } }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。