#include <fstream>#include <ios>#include <iostream>#include <string>intmain(){std::fstreamfs;fs.exceptions(std::ios::failbit|std::ios::badbit);// 例外を有効化するtry{fs.open("./temp.txt",std::ios_base::out|std::ios_base::in|std::ios_base::trunc);if(!fs.is_open()){throwstd::runtime_error("Failed to open file");// ファイルが開けなかった場合}inta=1;longdoubleb=3.141592;std::stringc="hello";fs<<a<<" "<<b<<" "<<c<<std::endl;fs.seekg(0);intd;longdoublee;std::stringf;fs>>d>>e>>f;if(!fs){throwstd::runtime_error("Failed to read from file");// ファイルから読み取れなかった場合}std::cout<<d<<" "<<e<<" "<<f<<std::endl;}catch(conststd::exception&e){std::cerr<<"Error: "<<e.what()<<std::endl;return1;}return0;}
You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.