错误 C2064:术语的计算结果不是采用 3 个参数的函数

error C2064: term does not evaluate to a function taking 3 arguments

本文关键字:函数 参数 C2064 术语 计算 结果 错误      更新时间:2023-10-16

环境 :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;
}