V
vknid
Hello, I have a question. Its probably a very newbish question so please be
nice hehe. =D
I have been reading through C++ Programming Fundamentals, and have come a
crossed an example program that shows how to use the 'getline' function.
It said:
"The getline function allows you to specify how many bytes you will get from
the users input. Each character the user's types takes up one byte. So if,
in the getline function, you specify four bytes, and the user types in the
word 'computer', you will only retrieve 'comp', the first four letters."
Then gave the example:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
char text[10];
cout << "Please enter a word.\n";
cin.getline(text,10);
cout << text << endl;
return 0;
}
Ok so I did that and gave it a test. I'm also going to assume that "char
text[10];" is where I specify how many bytes the user can input (which would
be 10 bytes, or 10 characters, right?). So I run the program and type in
"Dictionary". The result was that the 'Y' was cut off.
That went wrong?
Thanks.
..vK
nice hehe. =D
I have been reading through C++ Programming Fundamentals, and have come a
crossed an example program that shows how to use the 'getline' function.
It said:
"The getline function allows you to specify how many bytes you will get from
the users input. Each character the user's types takes up one byte. So if,
in the getline function, you specify four bytes, and the user types in the
word 'computer', you will only retrieve 'comp', the first four letters."
Then gave the example:
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
char text[10];
cout << "Please enter a word.\n";
cin.getline(text,10);
cout << text << endl;
return 0;
}
Ok so I did that and gave it a test. I'm also going to assume that "char
text[10];" is where I specify how many bytes the user can input (which would
be 10 bytes, or 10 characters, right?). So I run the program and type in
"Dictionary". The result was that the 'Y' was cut off.
That went wrong?
Thanks.
..vK