#include <iostream>
#include<fstream>
#include<vector>
using namespace std;
void main()
{
vector<char>test;
int i=0,count=1,count1=0;
fstream openfile("d:\\程序\\练习专用\\hello.txt");
if(!openfile)
{
cout<<"open failed!"<<endl;
exit(1);
}
do{
test.push_back(openfile.get());
count1++;
if(test[i]==' ')
count++;
if(openfile.eof())
break;
i++;
}while(!openfile.eof());
cout<<"the acount of the string is:"<<count<<endl;
cout<<"all of them are show below:"<<endl;
for(i=0;i<count1;i++)
cout<<test[i];
cout<<endl;
}
温馨提示:答案为网友推荐,仅供参考