In my code, I made a string and I pushed that string to a stack. (I don't know if I did it correctly as I am new to C++ and the concept of stacks) But when I try to top (I think this outputs the first element in the stack) it doesn't work correctly. I get a conversion issue from char to string. Even if I cast it as char it doesn't work correctly. Is there some way to convert it? I am trying to get it to out put h.
I keep getting the error :
C:\main.cpp:15:37: error: invalid user-defined conversion from 'char' to 'std::stack >::value_type&& {aka std::basic_string&&}' [-fpermissive] nextWord.push(str[i + 1]);
#include <iostream>
#include <iomanip>
#include <map>
#include <string.h>
#include <stack>
using namespace std;
int main(){
std::stack<string> nextWord;
string str = "T<h>is is a test";
for(int i = 0; i < str.length(); i++){
if (str[i + 2] == '>' && str[i] == '<'){
nextWord.push(str[i + 1]);
}
}
while (!nextWord.empty()) {
cout << "String: " << nextWord.top();;
}
cout << nextWord.pop() << '>' ;
}