我正在尝试编写一个函数,但是我遇到了编译器错误。我做错了什么?如果真的很蠢,我很抱歉。它迟到了。
以下是代码:
#include <list>
#include <iostream>
std::list<std::string> insertinlist(std::list<std::string> listofitems, std::int iterator1, std::string newitem){
list<std::string>::iterator listofitemsiterator = listofitems.begin();
if(iterator1 <= listofitems.size()){
for(std::size_t i=0; i<iterator1; i++){
listofitemsiterator++;
}
listofitems.insert(listofitemsiterator, newitem);
}else std::cout << "U suck" << std::endl;
return listofitems;
}
所以是的......编译器给出了以下错误
g++ -Wall -g -std=c++11 *.cpp -o practice1
In file included from practice1.cpp:6:0:
insertinlist.h:4:78: error: expected identifier before ‘int’
std::list<std::string> insertinlist(std::list<std::string> listofitems, std::int iterator1, std::string newitem){
^
insertinlist.h:4:82: error: two or more data types in declaration of ‘iterator1’
std::list<std::string> insertinlist(std::list<std::string> listofitems, std::int iterator1, std::string newitem){
^
insertinlist.h:4:91: error: expected ‘)’ before ‘,’ token
std::list<std::string> insertinlist(std::list<std::string> listofitems, std::int iterator1, std::string newitem){
^
insertinlist.h:4:105: error: expected initializer before ‘newitem’
std::list<std::string> insertinlist(std::list<std::string> listofitems, std::int iterator1, std::string newitem){
答案 0 :(得分:3)
int
是内置类型。它不在namespace std
,只使用int
,而不是std::int
。