打印所有空白(实际上不打印任何标记)
Printing all Blanks (literally no tokens are printed)
基本上我的代码不打印令牌。它只是打印空白。我做错了什么?我已经就此问题咨询了许多其他指南,但我似乎无法理解我做错了什么。
谢谢。
#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;
}
这段代码对我有用:
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 != NULL)
{
double n = strtod(strp, NULL);
s.push(n);
cout << n << endl;
strp = strtok(NULL, " ");
}
return 0;
}
但是见鬼,这真的是C和C++的痛苦混合。你应该摆脱那些strcpy,strtok和strod函数。请改用 istringstream。
相关文章:
- 打印时有二叉树问题.用户输入不打印任何内容
- main() 中的 std::cout 在调试期间不会在调试控制台中打印任何内容
- cout 不打印任何内容到控制台
- 为什么字符串没有更新并且最终没有打印任何内容
- 我如何处理 TMP 以避免打印任何东西
- 泛型函数反向打印任何矢量,编译器出错
- Cout 一个字符串可以打印任何内容到屏幕上
- "cout<<count<<endl;"没有打印任何内容
- 为什么循环迭代不打印任何东西?
- 函数不打印任何 c++
- 下面的代码没有打印任何东西
- 我的 c++ 程序中的字符数组不会打印任何内容
- 如果否则错误:如何使其打印任何数字
- 在 C++ 中声明向量后无法打印任何内容
- 在模板功能中打印任何结构
- 如果找不到解决方案,我如何留下递归循环,而不会打印任何东西
- 我的程序不会打印任何内容...
- 我的 c++ 程序不打印任何字符,但是如果我将它们更改为 int,代码可以完美运行
- 尝试使用类,但未打印任何内容.不会生成任何错误.我错过了什么吗?
- 为什么 void 函数不打印任何C++内容?