| |

VerySource

 Forgot password?
 Register
Search
View: 660|Reply: 1

After cin.getline (), why is the content of the input buffer gone?

[Copy link]

1

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-1-23 16:00:01
| Show all posts |Read mode
A short program is as follows
int _tmain (int argc, _TCHAR * argv [])
{
char p [10];
char t [10] = "111111111";
char t1;
cout << t;
cin.getline (p, 4);
cout << p << endl;
int a;
cout << "here" << endl;
cin >> t;
cout << "here";
cout << t << endl;

}
Enter iloveyou
Shows as follows:
111111111iloveyou
ilo
here
here
Please press any key to continue ...

Question:
Why t output is (nothing (spaces or tabs or ...))
I think cout << t << endl; this sentence is definitely executed, at least endl has been output, then the content of my t, I can not see. Thank you very much!
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-12 17:15:01
| Show all posts
cout << "here" << endl;
cin.clear ();
cin >> t;
cout << "here";
cout << t << endl;

This can output
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list