help my C++ code with error: no match for ‘operator++’ (operand type is ‘std::vector<char>’)

#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iostream>
#include <vector>
#include <map>
typedef std::vector<std::vector<char> > LineWords;

using namespace std;
int main()
{
//take the input file name
char substitution[80], words[80];
cout << "\nEnter substitution file name: \n";
cin.getline(substitution , 80);
cout << "\nEnter word file name: \n";
cin.getline(words , 80);

//open the input file to read
ifstream substitutionFileout, wordFileOut;
substitutionFileout.open(substitution);
wordFileOut.open(words);

//checking if the input files (substitution and word) are valid
if(!substitutionFileout.is_open()|| !wordFileOut.is_open())
{
cout << "BAD FILE FILENAME" << endl;
exit(0);
}

//Reading substitution file
string line;
std::vector<std::vector<char> > lineWords;
std::vector<std::vector<std::vector<char> >> lines;
map<vector<char>, vector<char>> subt;
while(std::getline(substitutionFileout, line))
{
string::iterator it;
bool newString = true;
lineWords.clear();
for ( it = line.begin() ; it < line.end(); it++)
{
if(isspace(*it) || ispunct(*it))
{
newString = true;
continue;
}

if(newString)
{
lineWords.push_back(std::vector<char>());
newString = false;
}

lineWords[lineWords.size() - 1].push_back((*it));
}
if(lineWords.size() != 2)
{
lineWords.clear();
}

if(lineWords.size())
{
lines.push_back(lineWords);
subt.insert(lineWords[0], lineWords[1]);
}
}

if(!lines.size())
{
cout << "Empty Substitution file. Please check" << endl;
exit(0);
}

//Reading word file and replacing
//map<vector<char>, vector<char>>::iterator it1;
std::vector<char> word;
while(std::getline(wordFileOut, line))
{
string::iterator it;
bool newString = true;
for ( it = line.begin() ; it < line.end(); it++)
{
if(isspace(*it) || ispunct(*it))
{
if(subt.find(word) == subt.end())
{
for(unsigned int i = 0; i < word.size();)
{
cout << word[i];
i+=1;
}
}
else{
vector<char> newWord = subt[word];
for(unsigned int i = 0; i < newWord.size();)
{
cout << newWord[i];
i+=1;
}
}
newString = true;
cout << *it ;
continue;
}
if((*it) == '\0')
{
if(subt.find(word) == subt.end())
{
for(unsigned int i = 0; i < word.size();)
{
cout << word[i];
i+=1;
}
}
else{
vector<char> newWord = subt[word];
for(unsigned int i = 0; i < newWord.size();)
{
cout << newWord[i];
i+=1;
}
}
newString = true;
cout << endl;
}

if(newString)
{
word.clear();
newString = false;
}

word.push_back((*it));
}
}
return 0;
}
Your code is very hard to read since you didn't bother using code tags.
And you didn't indicate which line the error refers to. I can't see it.
And you didn't bother to say what the program does, either.
Why all the C-strings, you really should be using C++ strings instead of the C-strings and vector of char.
The std::map stores its elements in std::pair so you need to pass a std::pair<vector<char>, vector<char>> as argument to insert.

 
subt.insert({lineWords[0], lineWords[1]});

Alternatively you can use emplace which will forward the arguments to the std::pair constructor.

 
subt.emplace(lineWords[0], lineWords[1]);
Topic archived. No new replies allowed.