我很确定这个bug应该在很久以前的早期版本的g ++中得到解决,但在我的情况下,我仍然会在给出命令时看到这个:
std::this_thread::sleep_for(std::chrono::milliseconds(10))
我得到的错误信息是:
In member function ‘long long int Iterator::next()’:
error: ‘std::this_thread’ has not been declared
答案 0 :(得分:0)
std::this_thread
位于C++11
。使用-std=c++11
标志。
#include <thread>
#include <chrono>
int main() {
std::this_thread::sleep_for(std::chrono::milliseconds(10));
}
编译:
g++ test.cpp --std=c++11 -g -Wall
版本:
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/5.2.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /build/gcc/src/gcc-5.2.0/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --disable-multilib --disable-werror --enable-checking=release --with-default-libstdcxx-abi=gcc4-compatible
Thread model: posix
gcc version 5.2.0 (GCC)
答案 1 :(得分:0)
确保您的标题中包含“thread”的C + 11标记和。