0
基本上我的代码不会打印令牌。它只是打印空白。我究竟做错了什么? 我在这个问题上咨询了许多其他指南,我似乎无法理解我做错了什么。打印所有空白(字面上不打印令牌)
谢谢。
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stack>
#include <stdexcept>
#include <string>
#include <stdlib.h>
#include <cstring>
using namespace std;
int main() {
stack<double> s;
string str = "";
getline(cin, str);
char *cstr = new char [str.length()+1];
strcpy(cstr, str.c_str());
char* strp = strtok(cstr, " ");
while (strp != 0){
double n = strtod(cstr, &strp);
s.push(n);
cout << strp << endl;
strp = strtok(0," ");
}
return 0;
}
你提供什么输入? – 2014-12-07 09:36:37
'double n = strtod(cstr,&strp);'错了,应该是'double n = strtod(strp,&other_pointer);' – BLUEPIXY 2014-12-07 09:37:40
@退休忍者2 3 + //输出是3个空格 – 2014-12-07 09:38:18