#include<string>int acnt=0,ecnt=0,icnt=0,ocnt=0,ucnt=0,cnt=0;string buf;while(cin>>buf)
{
for(ix=0;ix<buf.size();++ix)
{
switch(buf[ix])
{ case 'a':++acnt;++cnt;break;
case 'e':++ecnt;++cnt;break;
case 'i':++icnt;++cnt;break;
case 'o':++ocnt;++cnt;break;
case 'u':++ucnt;++cnt;break;
default:++cnt;break;
}
}
}
cout<<"A: "<<acnt<<endl
<<"E: "<<ecnt<<endl
<<"I: "<<icnt<<endl
<<"O: "<<ocnt<<endl
<<"U: "<<ucnt<<endl;
return 0;
}为何在VC6中无法通过?--------------------Configuration: temp - Win32 Debug--------------------
Compiling...
temp.cpp
C:\temp.cpp(5) : error C2146: syntax error : missing ';' before identifier 'buf'
C:\temp.cpp(5) : error C2501: 'string' : missing storage-class or type specifiers
C:\temp.cpp(5) : fatal error C1004: unexpected end of file found
Error executing cl.exe.temp.exe - 3 error(s), 0 warning(s)以上是错误信息,请帮忙!

解决方案 »

  1.   


    #include<string>
    using namespace std;
    试一下吧
      

  2.   

    你用的是支持命名空间的头文件,使用它的话必须以命名空间引用类,std::string buf,或像joke100所说的加上using std.你也可以用不使用命名空间的包含库,string.h(注意扩咱名.h)
      

  3.   

    #include <iostream>
    #include <string>
    using namespace std;
      

  4.   

    所有 STL 的符号位于 std 名字空间中, 你得在使用这些符号前加上using namespace std;