问题:C++ 以double类型读入
//请试下如下代码: #include<iostream> #include<fstream>
using namespace std;
int main(void) {
const char* inFile = "c:\\sample.txt"; ifstream strm;
strm.open( inFile, std::ios_base::in );
if ( !strm ) { cout<<"File: "<<inFile <<" opened failed! Exit..."; return -1; } double n=0; char ch;
while ( !strm.eof() ) { if ( strm>>n ) { cout<<n<<"\t"; } else { strm.clear(); } strm.get(ch); }
strm.close();
cout<<"任意键退出..."; cin.get();
return 0; } 如果你对C++ 以double类型读入这个问题有好的意见或
建议,请留言
|