cin >> a;

whenever i use cin >> a; I have to enter an integer, what am I doing wrong?
Maybe your keyboard doesn't have numeric keys?
for example:

int a;
cout << "enter pass: ";
cin >> a;
cout << "you entered: " << a;

will not accept letters, only numbers.
How come you are expecting to save letters in an integer variable? Why don't you declare the variable 'a' of the proper type?

1
2
3
4
char myStringOfCharacters[11];
std::cout << "Enter a single word (no spaces) not larger than 10 characters:  ";
std::cin >> myStringOfCharacters;
std::cout << "You entered:  " << myStringOfCharacters;


As you can see, you can store values appropriate to the type of variable.

Also, please use code tags when posting in this forum for maximum readability. See http://a.ly/5QH .
I highly recommend this instead:
1
2
3
4
std::string myStringOfCharacters;
std::cout << "Enter a single word (no spaces) larger as you want, doesn't matter :  ";
std::cin >> myStringOfCharacters;
std::cout << "You entered:  " << myStringOfCharacters;
I recommend strings too, but given the entry level of the OP I thought I should stick to the very basics.
I recommend strings too, but given the entry level of the OP I thought I should stick to the very basics.


IMO, strings are easier to use than char arrays...
Depends on the background of the programmer. If he/she has been "polluted" with a programming language with memory management, yes, strings will be easier. Otherwise a stack char array would be the easiest, I think.

In the end I think it is up to the OP which one is easier to understand. Good thing they are both now there.
im very new to cpp.

in:
char myStringOfCharacters[11];

can myStringOfCharacters be anything like:
char username[11];

and is [11] the maximum size of the word?
Yes, that's just the name I thought to be more descriptive in order to help you understand. The variable name can be anything that follows the rules for variable naming in C++. The word username is OK.

11 is the number of characters (because I declared the variable to be of type char, a character) that the array can hold. In strings it is customary (kind of mandatory) to always add a null char (value of zero) at the end of the string. It is a sentinel value to allow your code to discover where the string of characters end. Standard functions like strlen() depend on this sentinel value.

So 11 is the maximum number of characters you can hold in the example. Noting that you MUST use one of these for the sentinel value as explained above, you can deduct that yes, you can have a word stored there of a maximum of 10 characters.
whenever i use cin >> a; I have to enter an integer
int a;

Int stands for integer. If you don't know that, please, PLEASE for the next few months post ONLY in the "beginners" section. Then you can start posting in the "general c++ programming" section, and only when you get knowledge of OOP, windows functions and graphics, then post in the "windows programming" section.
Topic archived. No new replies allowed.