Register | Login | |||||
Main
| Memberlist
| Active users
| ACS
| Commons
| Calendar
| Online users Ranks | FAQ | Color Chart | Photo album | IRC Chat |
| |
0 user currently in Programming. | 3 guests |
Acmlm's Board - I2 Archive - Programming - C++ question.... | | | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread |
User | Post | ||
Sokarhacd Ball and Chain Trooper Resistance is Futile You Will Be Assimilated Hab SoSlI' Quch Level: 61 Posts: 548/1757 EXP: 1799888 For next: 76708 Since: 03-15-04 Since last post: 6 days Last activity: 4 hours |
| ||
ok...one thing I dont get...ive tried to store a sentence into a variable...ive tried name is the variable char name; string name; and then I do this cout << "Hello, what is your full name"< cout << "Ah, so your name is "< ....its probably something stupid. with that, I only get whats typed in before entering a space, like "Hello there", it spits out "Hello" and nothing else...can someone help.... (edited by Dcahrakos on 11-05-04 08:03 PM) |
|||
Dish Spiny Level: 38 Posts: 169/596 EXP: 355646 For next: 14801 Since: 03-15-04 From: Disch Since last post: 18 days Last activity: 18 days |
| ||
I can't really get into specifics because I find cout/cin to be horrendously stupid (look into printf() and scanf() for better alternatives unless you absolutly have to use cout/cin like for your school or something). Your 'name' variable should probably be a character array... not a single character nor a 'string' type: char name[80]; // will hold up to 79 characters (plus null termination) I would assume cin would give you the entire string typed by the user... but can't say for sure... I dodged cout/cin like the plague when I was learning. |
|||
Sokarhacd Ball and Chain Trooper Resistance is Futile You Will Be Assimilated Hab SoSlI' Quch Level: 61 Posts: 549/1757 EXP: 1799888 For next: 76708 Since: 03-15-04 Since last post: 6 days Last activity: 4 hours |
| ||
I can switch to printf and scanf, I just saw cin and cout, so I tried those, I also just tried printf and scanf and it gives me the exact same thing, and I make it a char name[90]; and it still only gave me everything before a space was entered. edit: ah ha.....I needed to use gets... apparently.... gets(name); worked perfectly..... (edited by Dcahrakos on 11-05-04 08:40 PM) |
|||
Dish Spiny Level: 38 Posts: 170/596 EXP: 355646 For next: 14801 Since: 03-15-04 From: Disch Since last post: 18 days Last activity: 18 days |
| ||
hmm... just tried it and got the same deal. gets() might be what you want for this... I just tried: char name[90]; printf("Input name:\n"); gets(name); printf("%s",name); it worked as expected, even with spaces. edit: haha... apparently you already figured it out ;D (edited by Disch on 11-05-04 08:43 PM) |
|||
Sokarhacd Ball and Chain Trooper Resistance is Futile You Will Be Assimilated Hab SoSlI' Quch Level: 61 Posts: 550/1757 EXP: 1799888 For next: 76708 Since: 03-15-04 Since last post: 6 days Last activity: 4 hours |
| ||
yeah, actually just figured it out...when like 2 minutes ago, and i edited right before you replied lol...well I guess thats solved lol... | |||
Euclid Cheep-cheep Level: 23 Posts: 119/193 EXP: 65528 For next: 2195 Since: 03-15-04 From: Australia Since last post: 24 days Last activity: 7 days |
| ||
proper way to use cin/cout in your case, c++ style. #include < iostream > #include < string > (don't forget these, else that string name won't work) // declaration string name; ... cout << "Hello, what is your full name?"; cin >> name; cout << "Ah, so your name is " << name << endl; a << can't be on the same line as >> since they're returning 2 different streams (input/output). *back to C* why use gets and risk entering more than 90 chars in this case? use fgets(stdin, name, 90) instead (i think i got them the right way around) |
|||
Dish Spiny Level: 38 Posts: 172/596 EXP: 355646 For next: 14801 Since: 03-15-04 From: Disch Since last post: 18 days Last activity: 18 days |
| ||
ah yeah... good call about the fgets. *Disch grumbles at command-prompt programming |
|||
Sokarhacd Ball and Chain Trooper Resistance is Futile You Will Be Assimilated Hab SoSlI' Quch Level: 61 Posts: 551/1757 EXP: 1799888 For next: 76708 Since: 03-15-04 Since last post: 6 days Last activity: 4 hours |
| ||
ah yes, fgets is better, and its actually fgets(name,90,stdin); thanks though. |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread |
Acmlm's Board - I2 Archive - Programming - C++ question.... | | | |