Been reading the forums all semester to try and debug and understand my runtime errors, never needed to actually post until now! I'm currently trying to operate with a vector that takes in a list of strings from a file, and will then take each row and create a separate vector to separate out each element of the string based on the delimiter (a semicolon in the text file), then combine them together. Essentially on paper it looks like table with generally 7 columns and a host of rows.
The error I'm currently receiving at runtime is:
/Users/beolachlasair/CS2 Progs/CS2Final_DB-build-desktop-Desktop_Qt_4_8_0_for_GCC__Qt_SDK__Debug/../CS2Final_DB/main.cpp:101: error: no matching function for call to 'std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::insert(int&, char&, char&)'
The code is as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
void view(vector<string> &vData)
{
vector< vector<string> > vRoster; // Create new vector with multiple dimensions
vector<string> vRowData; // Create new vector for row data separation
cout<<"Calling for loop"<<endl;
for (int i = 0; i < vData.size(); i++) // Loop through each element of passed vector
{
cout<<"Printing unformatted row "<<(i + 1)<<" based on i = "<<i<<endl;
cout<<vData[i]<<endl; //for runtime debug purposes
string temp = vData[i]; // temporary string is contents of vector at [i]th place
for (int j = 0; j < 7; j++) //new for loop to loop through that string
{
int p = temp.find(';'); //find the ';'
vRowData.insert(j, temp[0], temp[p-1]); //insert from beginning of string to where the ; was found
cout<<vRowData[j]<<"at j = "<<j<<endl; //debugging
temp.erase(0,p); // erase part of temp string already extracted.
}
}
Any suggestions on what's causing the runtime error would be appreciated! Not so much the approach I'm taking which is probably terrible (it's part of a project for submission, so I want to be able to have cracked the actual solution myself), but I won't know exactly what I need to change here til I can actually get it to run!
As far as I know there is no such a member function as insert(int&, char&, char&) in the class std::vector. All insert functions require that the first argument would be an iterator.
So this statement
vRowData.insert(j, temp[0], temp[p-1]); //insert from beginning of string to where the ; was found
I have never seen an error like that exactly, but I believe that when your error says "no matching function for call..." then that means that your prototypes/definitions and function calls are not all in agreement. Something somewhere is inconsistent. I would start by going back over your prototypes and making sure they match the function definitions exactly. But, I'm new too, so I could be way off.
;)P
I took a look at the documentation on here for vector.insert and it says it expects input operators as the last two arguments but there was an example where they passed in an array and that array+3 which looks similar to what you are doing.
Here:
1 2 3 4 5 6 7 8 9
for (int j = 0; j < 7; j++)
{
int p = temp.find(';');
for (int k = 0; k < temp.size(); k++)
tmp.push_back(temp[k]);
vRowData.insert(j, tmp.begin(), tmp.begin());
cout<<vRowData[j]<<"at j = "<<j<<endl; //debugging
temp.erase(0,p);
}
Why are you using the constant 7 in your loop? That looks dangerous considering you are using that index in your vector. What happens if you vector is has only 6 components?