Question:
Doubt in input-output streams in C++.?
?
2013-04-09 06:57:05 UTC
int main()
{
char a;
cout<<"Enter a text: ";
while(a!='\n')
{
cin.get(a);
cout< }

On executing this code in C++ compiler, the output is :
Enter a text: abcdef
abcdef

My question is "When we give cout<
Hope you understood my question...

Thanks in advance.
Four answers:
Cubbi
2013-04-09 18:42:14 UTC
standard input is line buffered by default. Until you press enter, no data is transferred to your program, regardless of how you're reading it - character by character or line by line.



It's usually possible to switch to unbuffered input (which you seem to want), but it requires OS-specific calls, such as tcsetattr()/stty on Unix or _getch() on Windows, or a specialized console library such as curses.
anonymous
2013-04-09 07:10:01 UTC
The unformatted get member function works like the >> operator with two exceptions. First, the get function includes white-space characters, whereas the extractor excludes white space when the ios::skipws flag is set (the default). Second, the get function is less likely to cause a tied output stream (cout, for example) to be flushed.



A variation of the get function specifies a buffer address and the maximum number of characters to read. This is useful for limiting the number of characters sent to a specific variable, as this example shows:



main()

{

char a[10];

cout << " Type a line terminated by carriage return\n>";

cin.get( a, 10 );

cout << ' ' << a;

}

In this example, you can type up to 9 characters and a terminating character. Any remaining characters can be extracted later
?
2016-11-02 14:54:37 UTC
the entire poem is extremely haunting FC and correctly offered. What i latest in analyzing became I have been given extra wrapped 'around the piece as I examine by using. It jogged my memory of two issues, being in a huge mausoleum as quickly as, feeling a lot extra closed in and afraid than i became interior the graveyard. the different became a early existence nightmare that repeated oftentimes The partitions have been the daylight hours homestead of revealed white flora on a chocolate history. At night in fitful sleep the flora became into rats racing around the room. A conceal below the mattress journey.
anonymous
2013-04-09 07:03:17 UTC
You should specify the size of string.



Eg. char a[10];



you can now read 9 charector string.



It can really solve your problem.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...