我正在制作一个小词汇记忆程序,其中的单词将随机闪现在我的意思中.我想使用标准的C++库,就像Bjarne Stroustroup告诉我们的那样,但我遇到了一个看似奇怪的问题.
我想将long整数更改std::string为能够将其存储在文件中.我也受雇于to_string()此.问题是,当我使用g ++(版本4.7.0,如其--version标志中所述)编译它时,它说:
PS C:\Users\Anurag\SkyDrive\College\Programs> g++ -std=c++0x ttd.cpp
ttd.cpp: In function 'int main()':
ttd.cpp:11:2: error: 'to_string' is not a member of 'std'
Run Code Online (Sandbox Code Playgroud)
我的程序给出了这个错误:
#include <string>
int main()
{
std::to_string(0);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是,我知道它不可能是因为msdn库清楚地说它存在并且早先关于Stack Overflow的问题(对于g ++版本4.5)说它可以用-std=c++0x旗标打开.我究竟做错了什么?
我正在尝试使用stoi将字符串转换为整数,但是它表示它没有声明.我有标准库和包含,但它仍然说"[错误]'stoi'未在此范围内声明"
代码如下:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
int main()
{
string end, init;
cout << "Introduction" << endl;
cout << "Start time (xx:yy)" << endl;
cin >> init;
string hours0 = init.substr(0,2);
int hours = stoi(hours0);
cout << hours << endl;
system("pause");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
请告诉我它为什么不起作用,或者给我第二个选择.
我有:
Windows 7/32bit上的-cygwin 1.7.25
-g ++ --version - > g ++(GCC)4.8.2
-libstdc ++.a - > gcc-g ++ - 4.8.2-1
试图制作一个c ++ Hello World:
#include <string>
int main()
{
std::string s = "123";
int i = std::stoi(s);
}
Run Code Online (Sandbox Code Playgroud)
编译给出:
$ g++ -std=c++11 main.cpp
main.cpp: In function ‘int main()’:
main.cpp:6:10: error: ‘stoi’ is not a member of ‘std’
int i = std::stoi(s);
Run Code Online (Sandbox Code Playgroud)
我搜索了几个小时,但我仍然找不到解决方案.这是什么问题?
我想用std::stoi.虽然我可以使用::atoi(str.c_str())它会使代码更清洁,如果这将工作.但Eclipse告诉我:
函数'stoi'无法解决
我查了一下
<string>包括在内,std::string,-std=c++0x -std=c++11也是设置的.是stoi()失踪的gcc,或者是不知何故我的错?
我正在使用gcc(Debian 4.7.2-4)4.7.2.
我收到以下错误:
prog.cpp:在成员函数'void Sequence :: GetSequence()':
prog.cpp:45:错误:'itoa'未在此范围内声明
我有包含cstdlib头文件,但它无法正常工作.
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;
template<typename T>
struct predicate :
public binary_function<T, T, bool>
{
bool operator() (const T& l,const T &r) const
{
return l < r;
}
};
class Sequence
{
public:
Sequence(vector<string> &v)
{ /* trimmed */ }
void GetSequence(void)
{
string indices = "";
char buf[16];
for( map<int, string>::iterator
i = m.begin(); i != m.end(); ++i )
{
indices …Run Code Online (Sandbox Code Playgroud) #include <iostream>
#include <string>
int main()
{
std::string test = "45";
int myint = stoi(test);
std::cout << myint << '\n';
}
Run Code Online (Sandbox Code Playgroud)
我在运行MinGW GCC 4.7.2的计算机上试过这段代码.它给了我这个错误:

我做错了什么,我从cppreference得到了这个.它完全相同的代码.它与此处描述的错误不同.
我需要unique_ptr在我的C++任务中使用.
我下载了一个新的编译器TDM-GCC-4.7.1并安装了它.然后我将GNU GCC Compiler的目录更改为选项中的安装路径:Setting->Compiler...->Toolchain Executable.
但它不起作用.当我定义一个unique_ptr.会发生错误:"unique pointer is not a command of 'std' "
使用智能指针的原因是提供强大的异常安全性,这也是此分配的要求.我只需要使用C++ 11的这个新功能......另外,我使用的操作系统是Window 7.
谢谢!