0

So, the goal of this function is for the user to give a array of strings, then using a previously defined function, determine if each individual string is a valid sentence. Unfortunately, I am completely lost about how to go about this.

int validSentences(const std::vector<std::string> paragraph)
{
    char* str;


    for (auto a : paragraph)
    {

        std::cout << a << " ";

        strcat(str, a.c_str);
    }
    std::cout << str << std::endl;


}

Here is what I have as a prototype, but I'm sure this is way off base.

I think a good start to my question would be this:

How would I go about taking each string within the given vector, and converting it to a cstring using an enhanced for loop that utilizes the auto keyword?

Captain Obvlious
  • 19,754
  • 5
  • 44
  • 74
Granzo
  • 1
  • 3
  • Super confusing – Granzo Sep 28 '17 at 16:15
  • First off, do not pass vector by value unless you really need. Then for your question, `for (auto a : paragraph)` gives `a` as a `std::string` which then you can convert to c_str by calling `c_str()`. Then on which you can call your previous function. – YiFei Sep 28 '17 at 16:26
  • I edited your tags to help you get more exposure. FWIW when posting a language specific question the tag for that language should almost always be the first one you choose. – Captain Obvlious Oct 04 '17 at 20:16
  • Mixing `char*` and `std::string` is a bad practice. And your function is a `join` function, i.e. [std::vector to string with custom delimiter](https://stackoverflow.com/questions/9277906/stdvector-to-string-with-custom-delimiter) – myaut Oct 04 '17 at 20:18

0 Answers0