c++ 文件的读写
文件 BookInfo.txt 关键字 书号 algorithms 034 analysis 034,050,067 computer 005,034 data 005,010,023 design 034 fundamental 023 introduction 010,050 numerical 050,067 structure 005,010,023
#include <iostream>
using namespace std;
#include <string>
#include <fstream>
int main ()
{
//读取文件的内容
ifstream file;
file.open("BookInfo.txt");
if(!file){
cout<<"File Open Error"<<endl;
return 1;
}
string line;
while(getline(file,line))
{
cout <<line << endl;
char *p;
p=strtok((char *)line.c_str()," ");
while(p!=NULL)
{
cout<<p<<'\n';
p=strtok(NULL," ");
}
}
return 0;
}