Почему std::stoi и std::array не компилируются с g++ c++11?C++

Программы на C++. Форум разработчиков
Ответить Пред. темаСлед. тема
Anonymous
 Почему std::stoi и std::array не компилируются с g++ c++11?

Сообщение Anonymous »


I've been learning C++ and using the Terminal for the last couple of months. My code was compiling and running fine using g++ and C++11, but in the last couple of days it started giving errors and I have had problems compiling since. The only programs I can compile and run depend on older C++ standards.

The errors I first got related to #include in the header file. Not sure why this happened, but I got around it by using boost/array instead. Another error I can't solve is with std::stoi. Both array and stoi should be in the C++11 standard library. I made the following simple code to demonstrate what's going on:

// // stoi_test.cpp // // Created by ecg // #include #include // stoi should be in here int main() { std::string test = "12345"; int myint = std::stoi(test); // using stoi, specifying in standard library std::cout 'atoi'? > int myint = std::stoi(test); > ~~~~~^~~~ > atoi > /usr/include/stdlib.h:149:6: note: 'atoi' declared here > int atoi(const char *); > ^ > array.cpp:13:27: error: no viable conversion from 'std::string' (aka > 'basic_string') to 'const char *' > int myint = std::stoi(test); > ^~~~ > /usr/include/stdlib.h:149:23: note: passing argument to parameter here > int atoi(const char *); > ^ > 2 errors generated. I also get these errors at compilation when using gcc or clang++ and with -std=gnu++11 (I guess they all depend on the same file structure). I also get the same error whether I specify std:: in the code, or if I specify using namespace std;

I worry that these issues arose because of the September Command Line Tools update via Xcode or because I installed boost and this somehow messed up my C++11 libraries. Hopefully there is a simple solution.

My system:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-> dir=/usr/include/c++/4.2.1 Apple LLVM version 5.0 (clang-500.2.76) (based on LLVM 3.3svn) Target: x86_64-apple-darwin12.5.0 Thread model: posix Thanks for any insight you can offer.


Источник: https://stackoverflow.com/questions/192 ... with-g-c11
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C++»