getline() a string giving difficulty
<p>i am doing a task where i am inputting ist no of times you want to have input and then i am inputting a full line by the use of getline but sime how i am not able to do that.</p>

<p>here when i try to input '1' as my no. of test cases it instantly gives '0' as answer and out of the loop why is not this cin>> test; here compatible with getline (cin,s);</p>

<pre><code>#include&lt;iostream&gt;
#include&lt;string&gt;

using namespace std;

int main()
{
    int test,j; 
    cin&gt;&gt;test;

    int len;
    string s;       
    for(j=1;j&lt;=test;j++)
    { 
        getline( cin,s);
        len = s.length();
        cout&lt;&lt;len;

    }
    return 0;
}   
</code></pre>

<p>the difficulty  </p>

<pre><code>input :
1
output:
0

expected
input:
1
Hello World
output
11
</code></pre>

<p>Well I mixed a little C to get My answer</p>

<pre><code>#include&lt;iostream&gt;
#include&lt;string&gt;
#include&lt;cstdio&gt;

using namespace std;

int main()
{
    int test,j; 
    scanf("%d\n",&amp;test);

    int len;
    string s;       
    for(j=1;j&lt;=test;j++)
    { 
        getline( cin,s);
        len = s.length();
        cout&lt;&lt;len;

    }
    return 0;
}   
</code></pre>
