I'm trying to build words inside of vectors by adding one character at a time but it won't let me add the char. How can I bypass this? Also, is my use of vector correct? Will this vector variable be able to store 50 words rather then just 50 characters?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
void Translator::toElvish(char out_s[], constchar s[])
{
int wordCount = 0;
vector <char> engW[50];
dictionary(Dictionary);
for (int i = 0; i < strlen(s); i++)
{
char c = s[i];
if (c !=' '||'\t'||'\n'||','||'.')
{
engW[wordCount] + c;
}
if (c == ' ')
{
wordCount + 1;
}
}
I have a suggestion: please use elements of modern C++ instead of leftovers from good old C.
Specifically, don't use char arrays if you are permitted to use std::string.
Furthermore, I don't truly understand what your code does; still my intuition tells me that you would be better off using std::string instead of std::vector<char>.
Note, std::string is in essence an alias for std::basic_string<char> so it's still a char container just like std::vector<char>.