vc++6.0怎么读取TXT文档中的数据行

弱弱的问下,vc++6.0怎么读取TXT文档中的数据行呢哪位大神知道给个明示

第1个回答  推荐于2016-07-02
给你个例子吧,举一反三嘛。 #include <iostream> #include <iomanip> #include <fstream> using namespace std; int main(){ char buffer[256]; ifstream myfile ("c:\\a.txt"); ofstream outfile("c:\\b.txt"); if(!myfile){ cout << "Unable to open myfile"; exit(1); // terminate with error } if(!outfile){ cout << "Unable to open otfile"; exit(1); // terminate with error } int a,b; int i=0,j=0; int data[6][2]; while (! myfile.eof() ) { myfile.getline (buffer,10); sscanf(buffer,"%d %d",&a,&b); cout<<a<<" "<<b<<endl; data[i][0]=a; data[i][1]=b; i++; } myfile.close(); for(int k=0;k<i;k++){ outfile<<data[k][0] <<" "<<data[k][1]<<endl; cout<<data[k][0] <<" "<<data[k][1]<<endl; } outfile.close(); return 0; }本回答被提问者采纳
相似回答