02-19-2009, 04:31 PM | #1 | ||
FFR Simfile Author
|
C++ programming question (Not sure where to put this thread)
Okay, so I'm rather new to C++ programming and I was wondering if someone out there could help me clear up some confusion.
I'm having trouble working with and understanding how to use character strings as input for a program. I have two examples of programs I've created with (what I figured would be working) character string input types. One of the two programs compiles and runs perfectly fine, while the other causes a ton of compiling errors. Quote:
This next one, however, does not. (Note that this program is much more complicated and that may very well be the reason for the problems. Also, please disregard any of my other newb mistakes and focus simply on the character string inputs and why they are causing problems. Also, this program was originally broken up into two parts, a header file and the regular .cpp file. I've been troubleshooting and was tired of switching back and forth between the two files and just put the class declaration, definition and functions in the .cpp file). Quote:
Any help on clearing up my confusion on this subject would be greatly appreciated. |
||
02-19-2009, 04:41 PM | #2 |
FFR Player
Join Date: Nov 2005
Age: 34
Posts: 853
|
Re: C++ programming question (Not sure where to put this thread)
My initial thought was that you ****ed up the classes, but they seem fine.
Okay, what's this: cin >> John.setName(inputName); I see what you're trying to do, but I don't think you can do that (Haven't done C++ in a while). Try: cin >> inputName; John.setName(inputName); Same for: cin >> John.setAge(inputAge); cin >> inputAge; John.setAge(inputAge);
__________________
www.freerice.com |
02-19-2009, 05:34 PM | #3 | |
FFR Veteran
Join Date: Oct 2006
Location: inside the box
Posts: 1,267
|
Re: C++ programming question (Not sure where to put this thread)
Quote:
That might have been one of those newb mistakes I wasn't suppose to point out. Anyway I would try doing what Necamus said.
__________________
|
|
02-19-2009, 05:37 PM | #4 |
tool
|
Re: C++ programming question (Not sure where to put this thread)
What Necamus said. You're trying to read in with a method call; while you think it might be able to streamline your code, there are some things you just can't do. On a related note, you should always read in to a String anyway to store for future use. If you really and truly only need to use the input one time, you can release the String after you use it.
__________________
|
02-20-2009, 10:53 AM | #5 |
FFR Player
|
Re: C++ programming question (Not sure where to put this thread)
All I can say is
Howdy Dan
__________________
|
02-20-2009, 03:03 PM | #6 | ||
FFR Veteran
Join Date: May 2006
Age: 33
Posts: 1,863
|
Re: C++ programming question (Not sure where to put this thread)
Quote:
Quote:
If your having problems still post what your debugger says. Last edited by argo15; 02-20-2009 at 03:15 PM.. |
||
02-20-2009, 04:01 PM | #7 |
Network Security Analyst
|
Re: C++ programming question (Not sure where to put this thread)
I'm happy I've been done with programming since last year. I'm no good at it.
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|