c++ - 为什么 stoi 会导致错误以及如何在 Makefile 中修复
问题描述
我一直在尝试运行使用 stoi 的代码,下面是 makefile,每次运行此代码时,我都会收到“错误:在此范围内未声明 'stoi'”,知道如何包含 C++ 11 编译器在make文件中
#compile and link the application
all: main
#run the application
run: main
./main
#link main.o, time.o, and date.o to excutuable main, with debug messages
and functions visible
debug: temp.o day.o cal.o
g++ -g -c -Duse_debug main.cpp
g++ -g -o main main.o temp.o day.o cal.o
#link main.o, temp.o, and day.o to executable main
main: main.o temp.o day.o cal.o
g++ -g -o main main.o temp.o day.o cal.o
#compile the main.cpp to main.o
main.o: main.cpp
g++ -g -c main.cpp
#compile the temp.cpp to temp.o
temp.o: temp.cpp
g++ -g -c temp.cpp
#compile the day.cpp to day.o
day.o: day.cpp
g++ -g -c day.cpp
#compile the cal.cpp to cal.o
cal.o: cal.cpp
g++ -g -c cal.cpp
#remove built files
clean:
rm -rf main main.o temp.o day.o cal.o *~
这是使用 stoi 的部分的示例代码,
#include <iostream> //cin and cout
#include <string> //stoi(), getline()
#include <cctype> //isdigit()
using namespace std;
int main()
{
int input;
string inputS;
cin>> inputS;
input = stoi(inputS); //converts inputStr to int type
return 0;
}
解决方案
推荐阅读
- python - 我的线性回归模型显示分数为 10%,我该如何改进它?
- php - LAST_INSERT_ID() 无法使此代码工作
- windows - 在 Windows 7 Enterprise 下禁用 Powershell 2.0
- ms-word - 创建一个 VSTO Word 插件,然后按下链接按钮打开文件
- c++ - char 指针或 char 变量的默认值是多少
- maven - 使用 Accessmbly 插件构建 Maven 失败
- javascript - 如何使用 fast-csv npm 将新行或新行的数据(新行)附加到现有的 csv 文件
- java - 请求获取参数(
) 返回空值 - javascript - Asp.Net Java 脚本根据循环后面的代码更改 Gridview 行颜色
- optaplanner - 将医院病床规划 (PAS - 患者入院安排)) 与我的网络应用程序集成