I want to store character in the vector. But it's not working when I wanted to push back the matching character.
Error is showing in this line -
v.push_back(arithmetic_operator[i]);
The whole code is -
#include<bits/stdc++.h>
using namespace std;
int main()
{
vector<char>v;
char str[100];
gets(str);
char *ptr;
ptr = strtok(str, " ");
char arithmetic_operator[6][6] = {"+", "-", "*", "/", "%", "="};
while(ptr !=NULL)
{
// arithmetic operator
for(int i=0; i<sizeof(arithmetic_operator); i++){
if(strcmp(arithmetic_operator[i], ptr) == 0)
{
v.push_back(arithmetic_operator[i]);
}
else
{
continue;
}
}
ptr = strtok(NULL, " ");
}
for (auto it = v.begin(); it != v.end(); it++)
{
cout << *it << " ";
}
return 0;
}
When the input is a = b + c, expected output will be =,+