楼上说的有点小问题,其实你的代码根本没错只是预编译部分加的不对而已。
改成下面这样就行了:
#include
#include
#include
using namespace std; //不要屏蔽
int main()
{
ifstream fout;
fout.open("bianyi.cpp");
int a=fout.get();
int i=0;
int shuzu[100];
while(a!=EOF)
{ shuzu[i]=a;
i++;
a=fout.get();
}
int i1=0;
char fuzhu[50];
while( shuzu[i1]!=32 && shuzu[i1]!=10)
{
fuzhu[i1]=(char)shuzu[i1];
cout<
i1++;
}
string str;
str=fuzhu;
cout<
}
错误有三:
1.#include< string > 改为#include
2.string str;字符串不能这样定义,必须定义成char str[50];
3.str=fuzhu; 赋值不能这样,采用下面的方式:
for (int n=0; i<50; n++)
str[n] = fuzhu[n];
自己改正看看。