- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
过去几个月我一直在学习 C++ 和使用终端。我的代码使用 g++ 和 C++11 编译和运行良好,但在过去的几天里它开始出错,从那以后我在编译时遇到了问题。我唯一可以编译和运行的程序依赖于旧的 C++ 标准。
我首先得到的错误与头文件中的#include
//
// stoi_test.cpp
//
// Created by ecg
//
#include <iostream>
#include <string> // stoi should be in here
int main() {
std::string test = "12345";
int myint = std::stoi(test); // using stoi, specifying in standard library
std::cout << myint << '\n'; // printing the integer
return(0);
}
尝试使用 ecg$ g++ -o stoi_trial stoi_trial.cpp -std=c++11 进行编译
array.cpp:13:22: error: no member named 'stoi' in namespace 'std'; did you mean '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.
在使用 gcc 或 clang++ 和 -std=gnu++11 时,我在编译时也会遇到这些错误(我猜它们都依赖于相同的文件结构)。无论我在代码中指定 std::还是指定 using namespace std;,我也会遇到同样的错误;
我担心这些问题的出现是因为 9 月通过 Xcode 更新了命令行工具,或者是因为我安装了 boost,这不知何故弄乱了我的 C++11 库。希望有一个简单的解决方案。
我的系统:
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
感谢您提供的任何见解。
最佳答案
clang有一个奇怪的stdlib,编译的时候需要加上下面的flag
-stdlib=libc++
你的代码片段可以在我的 mac 上运行
g++ -std=gnu++11 -stdlib=libc++ test.cpp -o test
这answer描述问题
关于c++ - 为什么 std::stoi 和 std::array 不能用 g++ c++11 编译?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19285775/
I was wondering which way is the most recommended one in modern C++ to convert a string to a numb
我有: -Windows 7/32 位上的 cygwin 1.7.25 -g++ --版本 --> g++ (GCC) 4.8.2 -libstdc++.a --> gcc-g++-4.8.2-1 尝
我已经在 my posts 之一中询问过关于 boost::lexical_cast 的替代方案的问题,在许多回复中,我有一个建议 stoi 作为可行的替代方案。 我决定对其进行测试,令我惊讶的是,此
我正在使用最新版本的 C++,我正在尝试运行以下代码。但是,它一直告诉我 stoi “未在此范围内声明”。我是 C++ 的新手,所以如果您有任何想法,请分享。 #include using name
这个问题在这里已经有了答案: Function stoi not declared (13 个答案) 关闭 8 年前。 我正在尝试使用 stoi() 将 string 转换为 int 但我收到的错误
我正在通过编写来自用户的简单输入/输出来练习我的 C++。我现在已经搜索了一个多小时如何将字符串转换为 int。每个答案都是不同的,并且需要其他东西。 我正在使用 Code::Blocks v.13.
这个问题在这里已经有了答案: cygwin g++ std::stoi "error: ‘stoi’ is not a member of ‘std (4 个答案) 关闭 6 年前。 所以这个错误已
我有这个代码,它给我错误 terminating with uncaught exception of type std::out_of_range: stoi: out of range 我已经确定
我正在尝试将字符串解析为整数,但我不确定自己做错了什么: string input; cin >> input; int s = std::stoi(input); 这不会构建并引发错误:“stoi”
我正在使用代码块,但我无法使 stoi() 函数正常工作。我阅读了有关此问题的其他问题,但无法解决。我检查了 C+11,我正在使用命名空间 std 并且我有字符串 header 。我不知道如何解决这个
我是 Java 新手,我正在寻找 Java 中 C++ 中的类似 stoi() 的函数。 我想要这样的: 如果有像“123ABC”这样的字符串,我想提取整数中的“123”并获取“A”的索引。 我一直在
正如您所知,std::sto* 函数系列的工作方式是读取字符串中的数字,直到找到非数字,如下所示: std::string pseudoNum = "123haha"; int num = std::
我尝试编写一个将数字字符串转换为整数的函数。使用g++ 9.2.0在VS代码上运行代码时,输出错误,但是在repl.it上运行时,输出正确。这是我的代码: #include #include
我对传递到 std::stoi 的整数字符串的限制感到困惑。一个整数是 32 位的,我没记错吗?在带符号的 32 位整数中,范围可以从 −2,147,483,648 到 2,147,483,647。我
我只是通过 HackerRanks 练习我的 C++,我正在做这个问题: Problem Statement You are given an integer N. Find the digits i
我有以下测试程序: #include int main(int argc, char* argv[]) { try { return std::stoi("300012723
我上周为一项作业创建了一个复数类,我们的下一个作业是将此类修改为模板类。部分赋值重载了提取运算符,最初只处理 int 时,我将整个输入行作为一个字符串,并为实部和虚部制作子字符串,然后我使用 stoi
大多数日常用例都已转换为标准库中可用的函数。但是,我想知道其中一些是如何在幕后工作的。比如 std::stoi 背后的实际代码是什么? 最佳答案 最直接的方法是调用适当的 C 函数,在本例中为 str
c++的stoi函数定义为: int stoi(const std::string& str, std::size_t* pos = 0, int base = 10); 如您所见,base 参数默认
我正在尝试使用 stoi将字符串转换为整数,但它说它没有声明。我有标准库和 包括在内,但它仍然显示 [Error] 'stoi' was not declared in this scope 代码如下
我是一名优秀的程序员,十分优秀!