OS is windows.
操作系统是windows操作系统。
I'll start off by saying that I have no experience with C++, or any other compiled language. I've used CPython a bit and am familiar with that, but, until earlier today, I'd never even glanced at C++ source.
我首先要说的是,我没有使用c++或任何其他编译语言的经验。我已经使用过CPython,并且对此很熟悉,但是,直到今天早些时候,我还从未浏览过c++源代码。
I'm trying to teach myself C++, so I've been playing around with it a bit, and one problem I'm having is the error:
我试着教自己c++,所以我一直在玩它,我遇到的一个问题是错误:
error: 'to_string' was not declared in this scope
Apparently, to_string is a C++11 thing, which should be fine. I downloaded the latest MinGW, added it to my path - I have checked, and running
显然,to_string是一个c++ 11的东西,应该没问题。我下载了最新的MinGW,并将它添加到我的路径中——我已经检查过并运行了。
g++ - v
does indeed tell me that I have version 4.8.1 installed. The IDE I'm working with, Code::Blocks finds it no problem, but it simply won't use any of the C++11 stuff, giving me errors such as the one above. Things not exclusive to C++11 compile fine.
确实告诉我安装了4.8.1版本。我正在使用的IDE,代码::块发现它没有问题,但是它不会使用任何c++ 11的东西,给我上面的错误。不是唯一的c++ 11编译好的。
There is a section under compiler flags to "follow the C++11 language standard", which I have checked, but, even then, I get the same errors. I'm really not sure what's going on - I've looked this up, and all of the suggestions are to update either the IDE or MinGW (both of which are up to date), or to select that flag, which, as I said, is already selected.
在编译器标记下有一个部分“遵循c++ 11语言标准”,我已经检查过了,但是,即使这样,我也会得到相同的错误。我真的不知道发生了什么——我已经查过了,所有的建议都是更新IDE或MinGW(两者都是最新的),或者选择那个标志,正如我说的,它已经被选中了。
Does anyone with more experience with C++ have any idea what might be going on?b
有没有人对c++有更多的经验?
3 个解决方案
#1
10
My understanding is that, other than regex
support, G++'s C++11 support is largely complete with 4.8.1.
我的理解是,除了regex支持之外,g++的c++ 11支持基本完成了4.8.1。
The following two links highlight the status of C++11 support in G++ 4.8.1 and libstdc++:
以下两个链接显示了在g++ 4.8.1和libstdc++中c++ 11支持的状态:
- C++11 status in GCC 4.8.x.
- c++ 11在GCC 4.8.x中的状态。
- C++11 status in libstdc++. Note that this is for the latest SVN release, not tied to a specific G++ release; therefore expect it to be "optimistic" with respect to G++.
- c++在libstdc + + 11的地位。注意,这是最新的SVN版本,而不是绑定到特定的g++版本;因此,期望它对G++“乐观”。
To compile C++11 code, though, you need to include the command line flag -std=c++11
when you compile.
要编译c++11代码,需要在编译时包含命令行标志-std=c++11。
#2
1
std::string is not compliant; it still uses legacy (and buggy especially with threads) 'copy on write' behavior. You might be able to use __gnu_cxx::__vstring as a workaround.
std::string不兼容;它仍然使用遗留系统(特别是带有线程的bug)“写复制”行为。您可能可以使用__gnu_cxx::__vstring作为一个工作区。
"Class template basic_string Partial Non-conforming Copy-On-Write implementation"
“类模板basic_string部分不一致的复制-写入实现”
http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.200x https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21334
http://gcc.gnu.org/onlinedocs/libstdc + + /手册/ status.html # status.iso.200x https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21334
Related: Does g++ meets std::string C++11 requirements
相关:g++是否满足std::字符串c++ 11要求。
#3
0
The g++ 4.8 series was not complete with regard to the core language. The following compiles and runs with g++ 4.9 and higher (and also with clang++ 3.3 and higher), but not with g++ 4.8.5 (or with any previous member of the g++ 4.8 series).
g++ 4.8系列在核心语言方面并不完整。下面的编译和运行是g++ 4.9和更高版本(也有clang++ 3.3和更高版本),但是没有使用g++ 4.8.5(或者与任何前g++ 4.8系列的成员一起使用)。
#include <iostream>
void ordinary_function (int&) { std::cout << "ordinary_function(int&)\n"; }
void ordinary_function (int&&) { std::cout << "ordinary_function(int&&)\n"; }
template<class T>
void template_function (T&) { std::cout << "template_function(T&)\n"; }
template<class T>
void template_function (T&&) { std::cout << "template_function(T&&)\n"; }
int main () {
int i = 42;
ordinary_function(42); // Not ambiguous.
ordinary_function(i); // Not ambiguous.
template_function(42); // Not ambiguous.
template_function(i); // Ambiguous in g++4.8.
}
#1
10
My understanding is that, other than regex
support, G++'s C++11 support is largely complete with 4.8.1.
我的理解是,除了regex支持之外,g++的c++ 11支持基本完成了4.8.1。
The following two links highlight the status of C++11 support in G++ 4.8.1 and libstdc++:
以下两个链接显示了在g++ 4.8.1和libstdc++中c++ 11支持的状态:
- C++11 status in GCC 4.8.x.
- c++ 11在GCC 4.8.x中的状态。
- C++11 status in libstdc++. Note that this is for the latest SVN release, not tied to a specific G++ release; therefore expect it to be "optimistic" with respect to G++.
- c++在libstdc + + 11的地位。注意,这是最新的SVN版本,而不是绑定到特定的g++版本;因此,期望它对G++“乐观”。
To compile C++11 code, though, you need to include the command line flag -std=c++11
when you compile.
要编译c++11代码,需要在编译时包含命令行标志-std=c++11。
#2
1
std::string is not compliant; it still uses legacy (and buggy especially with threads) 'copy on write' behavior. You might be able to use __gnu_cxx::__vstring as a workaround.
std::string不兼容;它仍然使用遗留系统(特别是带有线程的bug)“写复制”行为。您可能可以使用__gnu_cxx::__vstring作为一个工作区。
"Class template basic_string Partial Non-conforming Copy-On-Write implementation"
“类模板basic_string部分不一致的复制-写入实现”
http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.200x https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21334
http://gcc.gnu.org/onlinedocs/libstdc + + /手册/ status.html # status.iso.200x https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21334
Related: Does g++ meets std::string C++11 requirements
相关:g++是否满足std::字符串c++ 11要求。
#3
0
The g++ 4.8 series was not complete with regard to the core language. The following compiles and runs with g++ 4.9 and higher (and also with clang++ 3.3 and higher), but not with g++ 4.8.5 (or with any previous member of the g++ 4.8 series).
g++ 4.8系列在核心语言方面并不完整。下面的编译和运行是g++ 4.9和更高版本(也有clang++ 3.3和更高版本),但是没有使用g++ 4.8.5(或者与任何前g++ 4.8系列的成员一起使用)。
#include <iostream>
void ordinary_function (int&) { std::cout << "ordinary_function(int&)\n"; }
void ordinary_function (int&&) { std::cout << "ordinary_function(int&&)\n"; }
template<class T>
void template_function (T&) { std::cout << "template_function(T&)\n"; }
template<class T>
void template_function (T&&) { std::cout << "template_function(T&&)\n"; }
int main () {
int i = 42;
ordinary_function(42); // Not ambiguous.
ordinary_function(i); // Not ambiguous.
template_function(42); // Not ambiguous.
template_function(i); // Ambiguous in g++4.8.
}