首页 > 解决方案 > 为什么 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;
}
 

标签: c++c++11

解决方案


推荐阅读