请高手看看下面的程序,怎么不对?

来源:百度知道 编辑:UC知道 时间:2024/06/18 09:02:52
string str2[10];
vector<double>Sample1;
vector<double>temp;

if(str2[1][0]=='+')
{
str2[1]="";
str2[1]="1";
for(i=2;i<4;i++)
{
temp=atof(str2[i]);
Sample1.push_back(temp);

}

}

错误显示:
E:\练习\string.cpp(50) : error C2664: 'atof' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
E:\练习\string.cpp(51) : error C2664: 'push_back' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const double &'
Rea

类型不对呀
temp=atof(str2[i]);
这面这句str2[i]返回的是string,而atof需要的参数是const char*,不能转换,atof的返回类型是浮点数,temp是vector,也不行。

Sample1.push_back(temp);
sample1是double的vector,怎么能添加一个temp这样一个vector类型的元素呢