c++ - Don't understand Insert function too well, getting an error I can't seem to get past -


i trying insert user inputted name pre-existing string, , keep getting error stating that:

"[error] no matching function call 'std::basic_string::insert(std::basic_string::iterator, std::string&)'" on line 25

code:

#include <iostream> #include <string>  using namespace std; string custname = " "; string firstname = " "; string midinitial = " "; string lastname = " "; string getfullname = ""; string comma = ",";  int getname() {     cout<<"please enter first name \n";     cin>>firstname;     cout<<"please enter middle initial \n";     cin>>midinitial;     cout<<"please enter 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 } 

std::string::insert doesn't have function signature like:

basic_string& insert( iterator pos, const basic_string& str ); 

update

custname.insert(custname.end(), getfullname); 

to:

custname.insert(custname.end(), getfullname.begin(), getfullname.end()); 

or

custname.insert(distance(custname.end(), custname.begin()), getfullname); 

Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -