str.push_back为什么这段程序在dev下能通过,在vc6.0下不能?
#include<iostream>
#include<vector>
//#include<stdlib.h>
#include<string>
using namespace std;
int main()
{
string str("hello");
for(int i=0;str[i]!='\0';i++)
{
cout<<str[i];
}
cout<<endl;
cout<<"the length of str = "<<str.size()<<endl;
str.push_back('h');
cout<<"the length of str = "<<str.size()<<endl;
str.push_back('\0');
cout<<"the length of str = "<<str.size()<<endl;
cout<<str<<endl;
//system("PAUSE");
return 0;
}
error C2039: 'push_back' : is not a member of 'basic_string<char,struct std::char_traits<char>,class std::allocator<char> >'
[解决办法]
#include<iostream.h>
...
去掉:
using namespace std;
[解决办法]
VC6对标准支持不好,所有STL的头文件,都以.h结尾的。
而且,没有std命名空间。
[解决办法]