#include
#include
#include
#include
#include
const char * file = "test.txt";
int main(){
using namespace std;
string lit = "It was a dark\n"
"and stromy day, and the full\n"
"moon glowed brilliantly.";
//文件输出流
ofstream fout;
fout.open(file,ios_base::out);
if(!fout.is_open())
{
cerr<<"Can't open "<< file <<" file for output.\n";
exit(EXIT_FAILURE);
}
fout<<lit;
fout.close();
//输入流
ifstream fin(file,ios_base::in);
string s;
while(getline(fin,s)){
char str[100];
//将string类型转为char[]
strcpy(str,s.c_str());
//字符串截取
char * p = strtok(str," ");
while(p!=NULL){
cout<<p<<endl;
p=strtok(NULL," ");
}
}
cin.get();
cin.get();
}