![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| Tags: cout, help, progrmaming, questions, tutorial |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |
| |||
| I'm not sure how you came to that conclusion based on that program. exactly how cin and cout works depends on which implementation of the STL you're using, and on the platform you're writing your program for - the C++ standard doesn't specify if or how any data is stored. before its transferred from the standard input device (which may have its own buffer - this is the case with keyboard input on Windows machines, but other platforms it may not be). Just to clarify, the standard input device could be anything. On your computer, it might be the keyboard buffer - but it could be, for example, a mobile phone keypad, or a network connection, depending what sort of device you're programming for. Its up to the O/S (Which might be windows/linux, or may be firmware stored on a flash ROM chip) to handle the standard input device. Understanding what goes on under the hood of cout and i/o streams isn't really very important - What is more important, with regards to streams, is that you can rely on stream objects to all behave in a consistant manner. That is to say, if you write a bit of code using cin/cout, you could replicate that same bit of code almost exactly with a stringstream (usually for string formatting or string parsing), or an fstream (file access). The point is that the family of 'stream' libraries in C++ are designed to behave the same regardless of what input or output devices or buffers they may be attached to Last edited by Bench : 07-19-2007 at 05:47 AM. |
| |||
| Like Bench, I'm not really sure how you arrived at the conclusion that you did. Could you explain what you mean by "input value" as well as what led you to that conclusion? I think I know what you mean by "input value" since you mention the command line, and you aren't working with the command line in terms of getting command line arguments and using them. However, it would be beneficial for you to explain a little bit more since it seems to be unclear for both Bench and me, which means that it could also be unclear for future readers that might have a similar idea. __________________ "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off." -- Bjarne Stroustrup, creator of what is now known as C++ For more quotes by Bjarne Stroustrup, check out http://www.research.att.com/~bs/bs_faq.html#really-say-that. |
| ||||
| Quote:
![]() Last edited by HelloWorld : 07-19-2007 at 10:08 AM. Reason: Making it clearer |
| |||
| If you are referring to something such as: Code: int n1 = 1, n2 = 2, n3 = 4; //unimaginative... I know :p cout << "Enter three integers: "; cin >> n1 >> n2 >> n3; Code: cout << "Hello World!" << endl;
(cout << "Hello World!") << endl; //same output as above
cout << ("Hello World!" << endl); //error because you are trying to treat the const char array/pointer with the value "Hello World!" as an output stream The same idea is true of the example with cin above: Code: cin >> n1 >> n2 >> n3; ((cin >> n1) >> n2) >> n3; //same as above cin >> (n1 >> (n2 >> n3)); //error because you are trying to treat n2 as an input stream __________________ "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off." -- Bjarne Stroustrup, creator of what is now known as C++ For more quotes by Bjarne Stroustrup, check out http://www.research.att.com/~bs/bs_faq.html#really-say-that. |
| |||
| That is true. Be aware that white-space characters include tabs, spaces and newlines. You don't necessarily need to use a space, in other words. ![]() __________________ "C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off." -- Bjarne Stroustrup, creator of what is now known as C++ For more quotes by Bjarne Stroustrup, check out http://www.research.att.com/~bs/bs_faq.html#really-say-that. |
| The Following User Says Thank You to rpgfan3233 For This Useful Post: | ||
HelloWorld (07-20-2007) | ||
![]() |
| Thread Tools | |
| Display Modes | |
| |