错误 C2064:术语的计算结果不是采用 3 个参数的函数
error C2064: term does not evaluate to a function taking 3 arguments
环境 :Visual Studio 2008 Professional Edition
我正在尝试调试十六进制到十进制的转换,但不幸的是得到"术语没有计算为需要 3 个参数的函数"此错误。任何人都可以建议如何解决这个问题吗?
法典:
#include <string>
using namespace std;
int main()
{
int stoi;
int number = 0;
string hex_string = "12345";
number = stoi(hex_string, 0, 16);
cout << "hex_string: " << hex_string << endl;
cout << "number: " << number << endl;
return 0;
}
这就是为什么你不应该做using namespace std;
。摆脱它并通过将std::
放在std
命名空间中的所有内容之前来修复程序。
#include <iostream>
#include <string>
int main()
{
int stoi;
int number = 0;
std::string hex_string = "12345";
number = std::stoi(hex_string, 0, 16);
std::cout << "hex_string: " << hex_string << std::endl;
std::cout << "number: " << number << std::endl;
return 0;
}
您也可以重命名stoi
整数,以免与std::stoi
冲突,但强烈建议不要在代码中使用using namespace std;
。
如果由于 Visual Studio 2008 不支持 C++11 而根本无法使用stoi
,并且无法升级到较新版本,请参阅此处了解替代方法。但从长远来看,如果可能的话,安装更新的 IDE 可能是一个更好的主意。
因为stoi
是来自string library
的函数,所以你不会将stoi重新定义为int stoi
。删除int stoi
它将成功。
像这样的完整代码
#include <string>
#include <iostream>
using namespace std;
int main()
{
int number = 0;
string hex_string = "12345";
number = stoi(hex_string, nullptr, 16);
cout << "hex_string: " << hex_string << endl;
cout << "number: " << number << endl;
return 0;
}
谢谢大家的回复! 在Visual Studio 2008上成功调试以将十六进制转换为十进制的最终代码
#include <iostream>
using namespace std ;
#include <sstream>
int wmain() {
int binNumber ;
unsigned int decimal;
string hexString = "0x3d"; //you may or may not add 0x before
stringstream myStream;
myStream <<hex <<hexString;
myStream >>binNumber;
cout <<binNumber <<decimal;
return 0;
}
相关文章:
- static_assert在宏中,但也可以扩展到可以用作函数参数的东西
- C++中的高效循环缓冲区,它将被传递给C样式数组函数参数
- 当从函数参数中的临时值调用复制构造函数时
- 如何从"decltype()"获取函数参数的数量<funtion>?
- 如何将lambda作为模板类的成员函数参数
- 模板参数推导失败,函数参数/参数不匹配
- 如何在C++中将迭代器作为函数参数传递
- 将函数参数"const char*"转换为"std::string_view"是
- C++ 如何将数组值解压缩为函数参数
- 主函数参数的属性
- 具有两个间接寻址运算符 (C++) 的函数参数的用途
- "Warning: Comma within array index expression"但逗号分隔函数参数
- 如何定义在用作函数参数时工作的类模板的转换
- 将函数参数完美转发到函数指针:按值传递呢?
- 为什么我不能将引用作为 std::async 的函数参数传递
- 什么..(省略号)作为函数原型中唯一的函数参数,C++?
- 是否可以就地构造一个固定大小的数组作为函数参数?
- 接受模板作为函数参数
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- Arduino 函数参数