Hello. I used to program in C# a little bit, but after reading some things I've decided to push forward on C++. I have some doubts though that I can't seem to find the answer anywhere.
#include "Hello World.h"
int main (int argc, char* argv[])
{
//std::cout%26lt;%26lt;"Hello, World!";
std::cout%26lt;%26lt;"Oh my lord. This is me toying with the programmming code C++";
char myLine[100];
std::cin.getline(myLine,100);
return 0;
}
1. Do I have to always include? [code]int main (int argc, char* argv[])[/code]
2. I want to print "Hello World!" and on a separate line "Oh my lord. This is me toying with the programming code C++"
3. What does std, cout, cin mean? Are they short for something else? I'd like to know that way I'll remember them easily.
Thanks for the help guys. :)
A few simple questions from a newbie. About certain code.?
1. Sort of, you need a main function, but it can look like: int main() only.
2. You want to print out an end of line which is the string std::endl, so std::cout %26lt;%26lt; std::endl; in between your lines should do it.
3. std is the standard namespace, cout means C output and C input for cin.
Reply:std just means to use the standard cout, not any other cout that might be lying around.
If you put this line after your includes
using namespace std;
then you can get rid of the std::
Then for doing a newline you should use endl;
cout %26lt;%26lt; "Hello, World!" %26lt;%26lt; endl;
All programs need a main.
cout is the standard character output stream
cin is standard character input stream
Reply:I don't know what you read that made go from C# to C++ but I'll try to answer your questions:
Unless you are righting a very specific and simple program using the VOID MAIN(){....} //uses no return statement
And perhaps some simple functions added to that, then you do not need to include any header files.
I can guarantee though that there is no header file to include called "Hello World.h" unless you created one for some strange reason with code in it.
you do not require int main(int argc, char * argv[]) //unless you need your program to accept arguments at the command line (in DOS this would be something like "C:\%26gt;MyProgram.exe ARGS" or in UNIX, "Guest@UnixServer%26gt;./MyExecutable ARGS"
cout is a function, in which you need to include iostream: #include%26lt;iostream%26gt;, cout means console-out and will display what ever you need to, to the console (the screen).
cin also comes from the iostream header file and means take console input (keyboard) and store in a variable: cin %26gt;%26gt; myString;
I am not too familiar with std:: and I believe it has something to do with telling the code to reference the standard library (the header files). I don't think it is necessary if you include the correct header(s) depending on what you need (iostream, string, math, vector, etc). The only time you would need it is if you created something else that used cout or cin which would not be too smart.
I would highly suggest you stick with C#. C++ is great and it is where I did most of my development in college and a little before, but C# is perfect for Windows programming or building Web applications.
Depending on the compiler of C++ you are using, syntax may vary.
Unless you have a specific need to stay with C++, you should do C#. They are similar in syntax but it is easier in C# to create console apps, standalone apps, and web apps. You can even get express editions for free of C#, VB, and VisualC++ from microsoft.
Reply:You dont have to include the file if the file is incorparted. I dont know whats inside the hello world.h headers though.
Mind you The onyl knowledge I have for C++ is the general knowledge since I am a vb.net guy.
I think the cout means Line Out. Pretty much like "print on the screen".
Then the char myLine[100]; declares a varible. I dont know what the hundred means, but I have a 99% hunch that its a buffer in bytes.
the cin means "get from the screen" and the two parameters you used mean that the input from the from the cin should be stored in the variable.
the std probably just means that its getting the functions from the string class.
then you just return zero as your not returning anything in the function.
I hope that helps. I dont know anything about C++. I would never do C++ unless I am a professional at it. Its just .. its such a STRONG and LOW LEVEL language that even a simple print, and get statements require tedious code.
heheh
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment