why getline is not working on string array

Oct 3, 2014 at 8:17pm

1
2
3
string yow[3][2];
    getline(cin,yow[0][1]);
    cout<<yow;


why is it not working?
Last edited on Oct 3, 2014 at 8:17pm
Oct 3, 2014 at 9:18pm
cout is demanding to be more specific
Oct 3, 2014 at 10:04pm
hello ,

just use ( std :: ) before getline() or use ( using namespace std;) before main function

like this

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
#include <string>

using namespace std;
int main ()
{
     string yow[3][2];
     getline(cin,yow[0][1]);
     cout<<yow;

     return 0;
}


here is output of this code

[[, ], [, ], [, ]]


see the online output of any code at this page :: http://codepad.org
choose your programming language and put your code in that form , then press submit
after a while you will see the output !!!
Last edited on Oct 3, 2014 at 10:05pm
Oct 3, 2014 at 11:00pm
You need to specify what element of your array you want to print.
Oct 3, 2014 at 11:03pm
here is output of this code
[[, ], [, ], [, ]]

No. It should ouptut the address of yow variable. Any other sesult can be only cause by non-standard extension. Check on online compilers which are sane (or at least tells which compiler they use):
http://ideone.com/7vhUVI
http://coliru.stacked-crooked.com/a/0400265bf7a49221
Those two do not allow to link directly to the code:
http://www.compileonline.com/compile_cpp11_online.php
http://melpon.org/wandbox/
Oct 3, 2014 at 11:29pm
your right MiiNiPaa

program will gets a line ( string ) as an input , then prints the address of yaw variable

for example :

input :1654654654
output : 0x7fff1e9653f0

but that website......

Sorry guys !!!
Oct 3, 2014 at 11:38pm
@jib even if i specify the output of the array it still gives me incorrect results
Oct 3, 2014 at 11:39pm
Show your updated code.
Oct 3, 2014 at 11:44pm
@miinPaa ill send you my code as a pm
Oct 3, 2014 at 11:46pm
the admin pin number is 0000
Oct 4, 2014 at 5:31am
1
2
3
cin>>name[counter][0];
cout<<"\tEnter Name:";
getline(cin,name[counter][1]);
Here is the problem
http://stackoverflow.com/questions/21567291/why-does-stdgetline-skip-input-after-a-formatted-extraction
Oct 4, 2014 at 7:26am
were you able to correct the my codes?
Oct 4, 2014 at 7:30am
thanks i was able to do it but is there any other way because the <limits> was not discussed to us yet
Oct 4, 2014 at 7:41am
Answer gives you 2 solutions and describes why second one is superior. Why everyone uses first one?

Use std::cin >> ws;
Alternatively, you can just pass large number (like 1000) as ignore() first parameter.
Oct 4, 2014 at 12:55pm
cout is demanding to be more specific
1
2
3
string yow[3][2];
    getline(cin,yow[0][1]);
    cout<<yow[0][1]; 
Topic archived. No new replies allowed.