#include <iostream>
#include <list>
using namespace std;
string song = "CDE";
int songlength = song.length();
int counter = 0;
int main() {
cout << songlength << endl;
for (int i = 0; i < songlength + 1; i++, counter++) {
list<string> songlist;
songlist.push_back(song[counter]);
if (counter <= songlength) {
}
}
}
I am a beginner and I do not know much about this programming language.
Error:
error: no matching function for call to 'std::__cxx11::list<std::__cxx11::basic_string<char> >::push_back(__gnu_cxx::__alloc_traits<std::allocator<char> >::value_type&)'
The class
std::stringdoes not have a constructor with the first parameter of the typechar.Either you need to declare the list like
or like
But in the last case you need to call the method
push_backlikeusing the constructor
Also you need to place the declaration of the list before the for loop. Otherwise within the loop the list is created anew in each iteration of the loop.
For example