Hello help with a program please

Hello guys i have encountered a little issue. I am doing a program which suppose to take up to a 1000 lines of code and print them backwards.
Here is my test code.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <string>
using namespace std;


int readData(string  line[]){
int numLine=0;
int i=1;

cin>>line[0];
while (i<10){
    numLine++;
    getline(cin,line[i]);
    i++;
}
return numLine;
}
void printLine(string line[], int x){
while (x>=0)
{
cout<<"\n";
cout<<line[x];
x--;

}
cout<<"\n";


}





int main(){
int x;
string line[1000];
x=readData(line);
printLine(line,x);
return 0;

}
}

when running a program the output prints in a weird manner. Last output is for some reason starts with a new line.....here is an example its working until last lane. and than it does new line and screws up the output. Please give advice.
aaaaaa
sssssssss
dddddddddddd
fffffffffffffff
sssssssssssssssssss
asdasdas asdasdasd
asdasdasdasda sadasdasdasd
asdasd
dd

dd
asdasd
asdasdasdasda sadasdasdasd
asdasdas asdasdasd
sssssssssssssssssss
fffffffffffffff
dddddddddddd
sssssssss

aaaaaa

Process returned 0 (0x0) execution time : 12.308 s
Press any key to continue.
In readData you return 10, but the last string you have is line[9] (starts from 0)
but it returns all the output it just spaces out the last one for some reason. how would you suggest to fix this bug?
The other problem, I think, is the difference between cin>> and getline (lines 10 and 13). getline discards the \n from the buffer, while cin>> does not. If I have them all the same, it seems to work for me
Topic archived. No new replies allowed.