#include <vector>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <stdlib.h>
using namespace std;
•
• //main func declaration etc...
•
//Vectors for storing information from file
vector<string> include;
vector<string> exclude;
string temp; //for storing whatever the stream is on
int len = atoi(puzzle_file >> temp); //first pos
int width = atoi(puzzle_file >> temp); //second pos
上面的代码应该读入一个文件并将数字存储在相应的整数中。尽管我的文件头中有#include <\cstdlib> 和#include <\stdlib.h>,但我收到一条错误消息“没有匹配函数来调用‘atoi’”。不确定从这里去哪里。在 stackoverflow 和其他论坛上做了一些研究,找不到任何真正帮助我的东西。有什么建议吗?谢谢
最佳答案
stoi
以 std::string
作为参数,而 atoi
以 const char*
作为参数。
并且不要忘记 stoi
是自 c++11 以来的新内容。
关于c++ - atoi() 没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42849750/