okay, so I'm extremely new to c++, never programmed before this and i'm learning with my boyfriend who has some experience but c++ is new to him too. He's been trying to explain sstream and string to me and i really just cant understand what I'm doing wrong and why. I was wondering if you guys could look at this and let me know what I'm messing up and if you have any tutorials ( i've read a bunch online and the only things i can find have so much other stuff i just dont understand/ haven't seen yet.) or if you could explain how it all works in the easiest way to understand I'd appreciate it so much. Thankss!
#include <isostream>
#include <string>
#include <sstream>
using namespace std;
Put [code][/code] tags around your code to make it easier to read.
1) main() must return an int
2) You have 2 variables named the same: the string/int are both called number.
3) number1 does not exist, so the line after does not make sense
4) return0 needs a space between the return and the 0.
Yea the iostream I misspelled, I actually retyped it again really quick since I didn't know know to copy the code over.
So the iostream and return is actually right in my code.
Does int and string have to be completely seperate variables? Like int a; string b;?
That's what's confusing me, and why do I have to use string instead of cin?
Coding another program I used both cin and getline and it completely wrecked almost all of it. Even if I used (cin, variable name).
I don't remember the tutorial I was using cause I'm not home but even when I copied the instructional code just changing the intergers and variables it came out wrong.
Does int and string have to be completely seperate variables? Like int a; string b;?
Um... yes. :/
How else would the compiler know which one you're referring to?
...why do I have to use string instead of cin?
Because cin isn't a type, while string is. cin is an object that you can use to get data from the console. It's like cout, but in reverse. :)
A string, on the other hand, is a type that can hold an arbitrary amount of data in the form of a string of text "such as this little string". It's extremely useful when you're working with text. :)
I don't remember the tutorial I was using cause I'm not home but even when I copied the instructional code just changing the intergers and variables it came out wrong.
I'd suggest that maybe you should start of programming by writing your own code instead of copying and pasting... that way you'll get to understand the language a bit better. ;)
But if you're trying to get a number input from the person viewing the program you'd use what? Cause all I've learned so far is you use int and cin together. But now the bf is telling me to stop using cin and just use getstring.
I have written a couple things by myself but I can't remember how to apply certain functions such as string, getstring and sstream :( it feels hopeless and this is only the beginning
Thats for c++ game programming though, but it does start at the beginning and assumes that the reader has no c++ knowledge, so it really does start at the beginning.
But if you're trying to get a number input from the person viewing the program you'd use what? Cause all I've learned so far is you use int and cin together. But now the bf is telling me to stop using cin and just use getstring.
There is no such function as "getstring" (at least not in the standard, and as far as I am aware of it). And I'd suggest you to not let yourself get taught by your boyfriend, unless he actually happens to be an expert programmer. I do have quite a bit of experience myself, but I wouldn't go so far as to say I am capable of teaching anyone. Pointing out mistakes yes, teaching no.
I don't want to hurt your relationship or anything, but didn't you already mention that you know your boyfriend is new to C++? C++ is a tricky language, and I wouldn't say that anyone less than an expert programmer should try to teach it. :(
I'd suggest starting from the beginning, and grabbing a single good to tutorial (an example of a good tutorial: http://cplusplus.com/doc/tutorial/ ) and sticking with it.
hanst- getline* ahah i always mix that up. my bad. My boyfriend has programmed a bunch of things before, and a couple of small things he's implemented into his work for himself and his other employees, Hes a very smart man and he learns fast so I trust what he's teaching me ( since he's new he wait till he understands what he's just learned and then teaches it to me ). Its just this part is giving me a hard time.
Albatross- Yeah, i've taken a look at other peoples codes for things that they've made and it looks difficult, especially not having prior experience. That was the tutorial I was looking at, and until i have some extra money for books i think i'll stick with that and hopefully progress and understand more.
Thanks for your input guys, hopefully i'll see you in the big kid's programming forums soon haha.