相关疑难解决方法(0)

g_s(mingw)说to_string不是std的成员

我正在制作一个小词汇记忆程序,其中的单词将随机闪现在我的意思中.我想使用标准的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旗标打开.我究竟做错了什么?

c++ mingw g++ tostring c++11

241
推荐指数
6
解决办法
35万
查看次数

功能stoi没有声明

我正在尝试使用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)

请告诉我它为什么不起作用,或者给我第二个选择.

c++ string int pointers

21
推荐指数
5
解决办法
13万
查看次数

cygwin g ++ std :: stoi"错误:'stoi'不是'std.的成员

我有:

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)

我搜索了几个小时,但我仍然找不到解决方案.这是什么问题?

cygwin g++ c++11

18
推荐指数
1
解决办法
2万
查看次数

libstdc ++不实现std :: stoi吗?

我想用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.

c++ gcc std c++11

15
推荐指数
2
解决办法
9498
查看次数

错误:未在此范围内声明'itoa'

我收到以下错误:
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)

c++

8
推荐指数
2
解决办法
6万
查看次数

std :: stoi的问题,不适用于MinGW GCC 4.7.2

#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得到了这个.它完全相同的代码.它与此处描述的错误不同.

c++ mingw

8
推荐指数
1
解决办法
1万
查看次数

如何更新code :: blocks以使用TDM-GCC?

我需要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.

谢谢!

c++ codeblocks

4
推荐指数
2
解决办法
2万
查看次数

标签 统计

c++ ×6

c++11 ×3

g++ ×2

mingw ×2

codeblocks ×1

cygwin ×1

gcc ×1

int ×1

pointers ×1

std ×1

string ×1

tostring ×1