Printing out vector char by char I have learned a bit of C in university and I'm now learning C++ independently. I'm trying to print out std::vector&lt;std::string&gt; char by char. I know, that in C, strings are arrays and are terminated by '\0' terminator. Can I assume the same thing in c++? I use C++14.

This works, but I'm unsure if it's the correct way to do this. I know, I can use getline(std::cin, line) to read from stream as well. Which one is more preferred? How would you make my code better?

using namespace std;

int main()
{
    cout &lt;&lt; "Enter text\n";

    // Get input
    vector&lt;string&gt; str;
    for (string temp; cin &gt;&gt; temp; ) {
        str.push_back(temp);
        // If input ends with enter, break loop
        if (cin.peek() == '\n') break;
    }
    cout &lt;&lt; "\n\n";

    // Output vector string by string
    vector&lt;string&gt;::iterator it;
    for (it = str.begin(); it != str.end(); ++it) {
        cout &lt;&lt; *it &lt;&lt; '\n';
    }
    cout &lt;&lt; "\n\n";


    // Output vector char by char
    it = str.begin();
    while (it != str.end()) {
        /* Is this (*it)[i] != '\0' correct? Are strings '\0' terminated in
         * c++ as well, and are they in vector&lt;string&gt; '\0 terminated? */
        for (size_t i = 0; (*it)[i] != '\0' ; ++i) {
            cout &lt;&lt; (*it)[i];
        }
    cout &lt;&lt; ' ';    
    ++it;   
    }
    cout &lt;&lt; "\n\n";
}
So the first thing you can do is to use container loops

for (std::string &amp;mystring : str) {
// do someting
}


The second thing would be to have a look at rbegin() and rend, which give you reverse_iterators. 

You can find a very good reference here: http://www.cplusplus.com/reference/string/string/rend/

Together you would get something like that

for (std::string &amp;mystring : str) {
    for (std::string::reverse_iterator rit=mystring.rbegin(); rit!=mystring.rend(); ++rit) {
        std::cout &lt;&lt; *rit;
    }
}