Discussion Forums > Technology
Programming Help! (C++)
xShadow:
A function that just takes in a character? Interesting. Well, maybe if you had something that printed out the character input into some kind of image file via a predefined array of places to paint, and randomized colors (though you'd likely want an X/Y offset for that).
(click to show/hide)I just finished up yet another class that solely focused on C programming (not C++; for some reason us computer engineers need hardcore C coding skillz). Well, actually, no, for the first few weeks we also converted our C code to assembly (that was fun! 20 lines -> 300 lines... but that was a bad code; it worked though).
I noticed that C++ has a few differences from C. Namely, that "cout" command. Is that another way to do "printf("%d",x)"? I've quite honestly never used that.
I've also never seen that "namespace". According to what I've read it's... kind of like using a .h file with declarations to things you want to use? Kinda confused here. That's kind of weird, what's the advantage of it to a header file?
Anyway, C++ seems to have some interesting stuff. I'll prolly be watching this thread because I wanna learn a bit more about what you can do differently in it, just for the heck of it (if the TC continues to ask questions here).
TMRNetShark:
--- Quote from: xShadow on May 04, 2011, 10:35:32 PM ---A function that just takes in a character? Interesting. Well, maybe if you had something that printed out the character input into some kind of image file via a predefined array of places to paint, and randomized colors (though you'd likely want an X/Y offset for that).
(click to show/hide)I just finished up yet another class that solely focused on C programming (not C++; for some reason us computer engineers need hardcore C coding skillz). Well, actually, no, for the first few weeks we also converted our C code to assembly (that was fun! 20 lines -> 300 lines... but that was a bad code; it worked though).
I noticed that C++ has a few differences from C. Namely, that "cout" command. Is that another way to do "printf("%d",x)"? I've quite honestly never used that.
I've also never seen that "namespace". According to what I've read it's... kind of like using a .h file with declarations to things you want to use? Kinda confused here. That's kind of weird, what's the advantage of it to a header file?
Anyway, C++ seems to have some interesting stuff. I'll prolly be watching this thread because I wanna learn a bit more about what you can do differently in it, just for the heck of it (if the TC continues to ask questions here).
--- End quote ---
Dude, it's an elective class, I don't care about it... I can never understand why people want to do this as a job. It's just an hour of listening to the really good teacher... well... teach. Then 5 hours of banging my head against something because of goddamn errors. hahah
Freedom Kira:
Meh, if you're good at it, you're good at it. It pays good too.
--- Quote from: xShadow on May 04, 2011, 10:35:32 PM ---A function that just takes in a character? Interesting.
--- End quote ---
Sure. A function can take in anything. It was just an example anyway.
--- Quote from: xShadow on May 04, 2011, 10:35:32 PM --- (click to show/hide)I just finished up yet another class that solely focused on C programming (not C++; for some reason us computer engineers need hardcore C coding skillz). Well, actually, no, for the first few weeks we also converted our C code to assembly (that was fun! 20 lines -> 300 lines... but that was a bad code; it worked though).
I noticed that C++ has a few differences from C. Namely, that "cout" command. Is that another way to do "printf("%d",x)"? I've quite honestly never used that.
I've also never seen that "namespace". According to what I've read it's... kind of like using a .h file with declarations to things you want to use? Kinda confused here. That's kind of weird, what's the advantage of it to a header file?
--- End quote ---
(click to show/hide)C is actually one of the most versatile (and probably the most powerful, in terms of ability) languages in existence. Modern OS's, including pretty much every Linux kernel in existence, and Windows, are built on C. C++ is a simple derivative of C that is heavily object-oriented. C programming is, however, considerably more difficult. Memory leaks and segmentation faults are the most common and frustrating problems you will encounter when programming in C.
Since OP is taking this as a tech elective, he's probably not going to be using most of the object-oriented features of C++. Which is unfortunate, because object-orientation is the whole point of C++.
cin/cout are easily my favorite C++ keywords. It just pipes shit to stdout. So yes,
--- Code: ---
cout << x << endl;
--- End code ---
does the same thing as
--- Code: ---
printf("%d\n", x);
--- End code ---
but is far simpler to type. (endl is "end line")
Note you can still use all your standard C functions like printf in C++.
Namespaces are a bit different from header files. You can #include header files as you do in C, with slightly different syntax.
A namespace is a predefined library of functions you can use. If you know any Java, "using namespace std" would be like "import java.lang.*" or something. The latter is not necessary to explicitly put into code, though.
Namespaces are specific to object-oriented languages like C++ and C#. Java uses what are called libraries that are pretty much the same thing.
Navigation
[0] Message Index
[*] Previous page
Go to full version