我正在尝试将用户输入的名称插入到预先存在的字符串中,并且我不断收到错误消息:
“[错误]没有匹配函数来调用'std :: basic_string :: insert(std :: basic_string :: iterator,std :: string&)'” 第25行
代码:
#include <iostream>
#include <string>
using namespace std;
string custName = " ";
string firstName = " ";
string midInitial = " ";
string lastName = " ";
string getFullName = "";
string comma = ",";
int getName()
{
cout<<"Please enter your first name \n";
cin>>firstName;
cout<<"Please enter your middle initial \n";
cin>>midInitial;
cout<<"Please enter your surname \n";
cin>>lastName;
getFullName = firstName+" "+midInitial+". "+lastName;
}
int addName()
{
custName.insert (custName.end(), ',');
custName.insert(custName.end(), getFullName);
}
int main ()
{
getName();
custName = getFullName;
getName();
addName();
getName();
addName();
getName();
addName();
cout<<custName
}
答案 0 :(得分:2)
std::string::insert 没有功能签名,如:
basic_string& insert( iterator pos, const basic_string& str );
更新
custName.insert(custName.end(), getFullName);
为:
custName.insert(custName.end(), getFullName.begin(), getFullName.end());
或
custName.insert(distance(custName.end(), custName.begin()), getFullName);