J
Jonathan
Hey again everyone! I have another question for you guys. I am trying to
erase a certain vector element based on what number the user selects.
Here is what I did:
case 'b' :
{
cout << "Please enter note number to clear: ";
cin >> clear_note;
clear_note = clear_note - 1;
vec.erase(clear_note);
ofstream rewrite("post.txt", ios:ut);
while (! rewrite) //check file open
{
cout << "Error opening output file!";
return -1;
}
while (j < vec.size()) // j is counter variable (set to 0 above)
{
rewrite << vec[j] << endl;
j++;
}
rewrite.close();
break;
}
When I do that, I get the following compile error:
Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\C++\notes.cpp" -o "C:\C++\notes.exe" -g3
-I"C:\Dev-Cpp\include\c++" -I"C:\Dev-Cpp\include\c++\mingw32"
-I"C:\Dev-Cpp\include\c++\backward" -I"C:\Dev-Cpp\include"
-L"C:\Dev-Cpp\lib"
C:/C++/notes.cpp: In function `int clear()':
C:/C++/notes.cpp:142: no matching function for call to `
std::vector<std::string, std::allocator<std::string> >::erase(int&)'
C:/Dev-Cpp/include/c++/bits/stl_vector.h:645: candidates are:
__gnu_cxx::__normal_iterator<_Tp*, std::vector<_Tp, _Alloc> >
std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<_Tp*,
std::vector<_Tp, _Alloc> >) [with _Tp = std::string, _Alloc =
std::allocator<std::string>]
C:/Dev-Cpp/include/c++/bits/stl_vector.h:668:
__gnu_cxx::__normal_iterator<_Tp*, std::vector<_Tp, _Alloc> >
std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<_Tp*,
std::vector<_Tp, _Alloc> >, __gnu_cxx::__normal_iterator<_Tp*,
std::vector<_Tp, _Alloc> >) [with _Tp = std::string, _Alloc =
std::allocator<std::string>]
Execution terminated
Any ideas as to why it is doing that? Thanks in advance for any help!!
-Jonathan
erase a certain vector element based on what number the user selects.
Here is what I did:
case 'b' :
{
cout << "Please enter note number to clear: ";
cin >> clear_note;
clear_note = clear_note - 1;
vec.erase(clear_note);
ofstream rewrite("post.txt", ios:ut);
while (! rewrite) //check file open
{
cout << "Error opening output file!";
return -1;
}
while (j < vec.size()) // j is counter variable (set to 0 above)
{
rewrite << vec[j] << endl;
j++;
}
rewrite.close();
break;
}
When I do that, I get the following compile error:
Compiler: Default compiler
Executing g++.exe...
g++.exe "C:\C++\notes.cpp" -o "C:\C++\notes.exe" -g3
-I"C:\Dev-Cpp\include\c++" -I"C:\Dev-Cpp\include\c++\mingw32"
-I"C:\Dev-Cpp\include\c++\backward" -I"C:\Dev-Cpp\include"
-L"C:\Dev-Cpp\lib"
C:/C++/notes.cpp: In function `int clear()':
C:/C++/notes.cpp:142: no matching function for call to `
std::vector<std::string, std::allocator<std::string> >::erase(int&)'
C:/Dev-Cpp/include/c++/bits/stl_vector.h:645: candidates are:
__gnu_cxx::__normal_iterator<_Tp*, std::vector<_Tp, _Alloc> >
std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<_Tp*,
std::vector<_Tp, _Alloc> >) [with _Tp = std::string, _Alloc =
std::allocator<std::string>]
C:/Dev-Cpp/include/c++/bits/stl_vector.h:668:
__gnu_cxx::__normal_iterator<_Tp*, std::vector<_Tp, _Alloc> >
std::vector<_Tp, _Alloc>::erase(__gnu_cxx::__normal_iterator<_Tp*,
std::vector<_Tp, _Alloc> >, __gnu_cxx::__normal_iterator<_Tp*,
std::vector<_Tp, _Alloc> >) [with _Tp = std::string, _Alloc =
std::allocator<std::string>]
Execution terminated
Any ideas as to why it is doing that? Thanks in advance for any help!!
-Jonathan