0
토큰을 대기열에 넣으려고합니다. 그러나 하나 이상의 숫자 (예 : 10, 123)가있는 숫자를 넣으려고하면 별도의 숫자로 읽습니다. 누군가 내가 뭘 잘못하고 있다고 말할 수 있습니까? 나는 문자열 삽입을 시도하고 추가 및 그들 중 누구도 그래서 이전 반복의 값을 보유하지 않는 를 다시 얻을 것이다마다 반복 TEMP2 TEMP3의 temp4 변수의 값에문제 문자열에 문자열 추가
queue <string> getTokens(string token){
int a = (int) token.length();
string temp;
queue <string> numbers;
char t;
for (int i =0; i <a; i++){
t = token[i];
while (!isdigit(t)){
if (t=='+' || t=='-' || t=='/' || t=='*' || t=='^'){
string temp1;
temp1 += t;
numbers.push(temp1);
temp1.clear();
}
else if (t=='(' || t==')'){
string temp1;
temp1 += t;
numbers.push(temp1);
temp1.clear();
}
else if (!isalpha(token[i-1]) && t == 'e' && !isalpha(token[i+1])){
string e = "2.718";
numbers.push(e);
}
else if (!isalpha(token[i-1]) && t == 'p' && token[i+1]== 'i' && !isalpha(token[i+2])){
string pi = "3.14169";
numbers.push(pi);
}
break;
}
//if it is one single number
if (!isdigit(token[i-1]) && isdigit(t) && !isdigit(token[i+1])){
string tt;
tt += t;
numbers.push(tt);
}
//if there is more than one number
else if ((isdigit(t) && isdigit(token[i+1])) || (isdigit(token[i-1]) && isdigit(t))){ //if it is a number
string temp2;
string temp3="k";
string temp4;
//cout << t;
//int j=1;
if(isdigit(token[i])){
temp2 += t;
cout<<"temp2 : "<<temp2<<endl;
cout <<"temp3 :" << temp3<<endl;
//temp2.clear();
temp3 +=temp2;
}
temp4.append(temp3);
temp4 +=temp3;
//cout<<"hi"<<endl;
cout << "This is temp4: " << temp4 <<endl;
//cout << "this is temp3: " << temp3<< endl;
//temp2.clear();
//cout<<temp2 << "yo";
//temp3.assign(temp2);
//cout << "temp3 is : "<< temp3;
}
else
continue;
}
return numbers;
}
int main(){
string expression;
getline(cin,expression);
cout << expression;
queue <string> ts;
ts= getTokens(expression);
}
케어 도움이 될 희망을 위해, 루프 외부를 선언을 취소하려고? 이것은 어딘가에 루프에 있습니까? t 란 무엇입니까? 토큰이란 무엇입니까? – mascoj
우리는 당신을 돕기 위해 좀 더 많은 정보가 필요합니다. –
[mcve]에 대해 읽어 보시고 알려주십시오. 여기에 표시 한 코드는 문자 그대로 무엇이든 할 수 있습니다. 어떤 유형의 변수 ('temp2'는 제외) 또는 초기화 방법은 알 수 없습니다. – user463035818