【发布时间】:2021-12-26 22:53:30
【问题描述】:
我正在为 gcc 使用最新的编译器。因此我的代码可以执行 to_String() 和 stoi() 但不幸的是,我试图编译我的代码的平台有一个以前的平台,我想将这两个函数添加到字符串类中,因此我可以在我的代码中使用它们没有任何问题。这是我得到的每个错误示例之一。
Cabinet.cpp:93:25: error: 'to_string' was not declared in this scope
cout << to_string(id) << " not found"<<endl;
LabOrganizer.cpp: In member function 'void LabOrganizer::findClosest(int, int, int)':
LabOrganizer.cpp:294:38: error: 'stoi' was not declared in this scope
cc = stoi(arr1[i].substr(1,1))-1;
【问题讨论】:
-
你是否尝试过包含命名空间,例如
std::to_string? -
@AlpE 不要做
using namespace std;并且要包含您希望调用的函数的正确标题。 -
with 1998 gcc你是考古学家吗? -
“将这两个函数添加到字符串类”的唯一实用方法是使用最新的更新您的 1998 标准库和编译器。如果由于某种原因无法完成,则需要使用 1998 年的 C++ 子集编写。
-
这些都不是
std::string(或任何其他类)的成员。没有什么能阻止您实现它们,而是将它们放在您自己(或全局)的命名空间中。
标签: c++ string gcc overloading c++98