Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><code>vector.size()</code> returns the size of a vector. You didn't put any string in the vector before the loop , so the size of the vector is 0. It will never enter the loop. First put some data in the vector and then try to add them. You can take input from the user for the number of string user wants to enter.</p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;string&gt; #include &lt;cctype&gt; using namespace std; int main(int a, char* b []) { vector&lt;string&gt; userString; string word; string sentence = ""; int SIZE; cin&gt;&gt;SIZE; //what will be the size of the vector for (int i = 0; i &lt; SIZE; i++) { cin &gt;&gt; word; userString.push_back(word); sentence += userString[i] + " "; } cout &lt;&lt; sentence; system("PAUSE"); return 0; } </code></pre> <p>another thing, actually you don't have to use a vector to do this.Two strings can do the job for you.</p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;string&gt; #include &lt;cctype&gt; using namespace std; int main(int a, char* b []) { // vector&lt;string&gt; userString; string word; string sentence = ""; int SIZE; cin&gt;&gt;SIZE; //what will be the size of the vector for (int i = 0; i &lt; SIZE; i++) { cin &gt;&gt; word; sentence += word+ " "; } cout &lt;&lt; sentence; system("PAUSE"); return 0; } </code></pre> <p>and if you want to enter string until the user wish , code will be like this:</p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;string&gt; #include &lt;cctype&gt; using namespace std; int main(int a, char* b []) { // vector&lt;string&gt; userString; string word; string sentence = ""; //int SIZE; //cin&gt;&gt;SIZE; //what will be the size of the vector while(cin&gt;&gt;word) { //cin &gt;&gt; word; sentence += word+ " "; } cout &lt;&lt; sentence; // system("PAUSE"); return 0; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload