#include<iostream>
#include<string>
#include<ctype.h>
#include<vector>
using namespace std;
int main(){
vector<string>temp;
int m = 0;
string strOperand = "10 7 5.0 * -";
string strCurData = "";
for (int i = 0; i < strOperand.size(); i++)
{
if (isdigit(strOperand[i]) || strOperand[i] == '.')
{
strCurData.push_back(strOperand[i]);
}
else
if (!isdigit(strOperand[i]) && strOperand[i] != '.'){
if (strOperand[i] == ' ')
{
temp[m] = strCurData;
strCurData = "";
m++;
}
else
if (strOperand[i] == '+' || strOperand[i] == '-' || strOperand[i] == '*' || strOperand[i] == '/' || strOperand[i] == '%' || strOperand[i] == '^')
{
temp[m] = strOperand[i];
m++;
}
else
if (strOperand[i]=='\0')
{
break;
}
}
}
cout << m;
}
我想将字符串拆分为一个向量,但是它变成了一个错误警告,表示向量下标超出了范围,我真的很担心这个,有人可以帮助我,谢谢!
答案 0 :(得分:1)
temp
为空,但您可以通过索引访问其不存在的元素。您描述的行为符合预期。