-
June 29th, 2011, 01:28 AM
#1
What is the function of cin.get(c)?
i know it takes one character at a time but if i give input HELLO WORLD what it will take then just H. And what will cout.put(c) print then?
-
June 29th, 2011, 04:51 AM
#2
Re: What is the function of cin.get(c)?
Write a little program and test by yourself.
See the documentation:
- http://www.cplusplus.com/reference/i...m/istream/get/ ,
- http://www.cplusplus.com/reference/i...m/ostream/put/ ,
- http://www.cplusplus.com/reference/iostream/cin/ ,
- http://www.cplusplus.com/reference/iostream/cout/ .
Edit: Sorry, I forgot to answer your questions.
Q: What is the function of cin.get(c)?
A: The function is to get one character.
Q: What will cout.put(c) print?
A: It will print the c character.
The following example will help you understand these functions
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main () {
char ch;
ofstream outfile ("test.txt");
do {
ch=cin.get();
outfile.put (ch);
} while (ch!='.');
return 0;
}
This example writes to a file everything the user types until a dot (.) is typed.
Last edited by olivthill2; June 29th, 2011 at 04:57 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|