0

Hi I have to do an assignment for a course that includes that I use new stream insertion and stream extraction techniques. On the lecture notes it briefly mentioned cin.get() and getline but not in a very descriptive way. Could anyone please summarize the use of get() when inputting more than a 1 digit float and int. Thank you so much.

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by firstPerson
0

example of cin.get().

say a file called num.txt contains the following :
12345677700234.

using cin.get() would first get the number 1, then it may be easier to imagine an arrow pointing to the number 2 , because the number 1 has already been extracted. Then using cin.get() again would ger the number 2, then an imaginary arrow would point to the next number, 3, so if you use cin.get() , then you would get the number 3, and the an imaginary arrow would point to the number 4, then if you use cin.get, you get 4, and so on.

here is an example.

file num.txt contains [123445];

//include all needed libraries.
//preprosessors directives.

int main()
{
ifstream file("num.txt)
...
...

int num;

while(!fil.eof())
{
cin.get(num);
cout<<num;
}

return 0;

}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.