注册 登录
编程论坛 C++教室

为什么不能预编译?

doom5211 发布于 2007-08-03 18:29, 526 次点击
本人在学习C++ Primer第三版,学到第六章碰到一个题目:写一个程序,已知下列字符串 "ab2c3d7R4E6",用find_first_of()查找每个数字字符,看上去很简单,我遍的程序如下:
#include <string>
#include <iostream>
int main()
{
string text("ab2c3d7R4E6");
string elem("0123456789");
int pos=0;
while((pos=text.find_first_of(elem,pos))!=string::npos)
{
cout<<"found the number at:"<<pos<<"\t element is"<<text[pos]<<endl;
++pos;
}
}
编译的时候却说主函数里的string是非法的定义,晕,我就是按书上的方法定义两个string类对象也有错啊? 我在VC6里编译的
到底怎么回事啊?
5 回复
#2
cfd2007-08-03 18:48

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

int main()

#3
antter2007-08-03 18:49
字面上理解,漏了 using namespace std;
#4
doom52112007-08-03 23:09
晕,这个都居然忘了.拖出去斩了
#5
xmt0072007-08-07 10:46

#6
孔令光2007-08-07 15:18
上边的程序要实现什么样的功能呢,find_first_of() 这个函数实现怎样的功能呢?谢谢指教
1