FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


C++ for beginners





bugra9
This tutorial for complete beginners.
Use a compiler like VC++ 6 or Bloodshed.


CODE

#include <iostream.h> //Includes iostream for I/O operations?!?!?!?!?!? LIEK

char f[50] = "Hello World!"; //Sets f to 50 character length and puts "Hello World!" in

int main() //Initialises main
{ //All code in Main goes after this
cout << f << "\n"; //Outputs whats in f then makes a new line ("\n")
return 0; //Ends the program
}//End of code for main
elekis
without speaking about the fact you need more point.

there is the exacly same thing but more powerful (and more c++


#include <iostream.h>
#include <string.h>
using namespace std;

int main()
{
string p = "hello world";
cout << p << endl;

return 0;
}

I thing it's better like that
snowboardalliance
Umm, if I had never seen C++ before I would just be lost from that. It's good to try to help people, but you can't really help beginners by showing them a 7 line code segment Hello World.
deepak
iostream.h? thats old

it should be #include<iostream>
Gieter
If you really want to learn C++, use a good tutorial like the one from cplusplus.com: http://cplusplus.com/doc/tutorial/.
Indi
elekis wrote:
without speaking about the fact you need more point.

there is the exacly same thing but more powerful (and more c++


#include <iostream.h>
#include <string.h>
using namespace std;

int main()
{
string p = "hello world";
cout << p << endl;

return 0;
}

I thing it's better like that

There are a couple of things wrong with that code, and a couple of things that could be done better. Here are the actual problems:
  1. The header <iostream.h> is not legal. It was never part of the standard, although it was common before the standard was finalized.
  2. The header <string.h> is not the header you think it is. That is the C header, with everything included into the global namespace. You want the C++ string header, which is <string>.

And here are some things that can be done better. When you're writing code to teach a complete beginner, it's always a really bad idea to start out by teaching them bad habits:
  1. It is a better idea to put the using directive in the smallest scope possible - in this case, at the top of main.
  2. It is a better idea to use the constructor idiom when constructing a variable. It is more clear that you are constructing something, and you're not relying on compiler optimizations to remove the unnecessary assignment.
  3. Is "p" really the best name for that variable? Why not something better, like "greeting"?

Here is the corrected code:
Code:
#include <iostream>
#include <string>

using namespace std; // <- You can use this here, but...

int main()
{
   // using namespace std; // ... this would be better
   
   string greeting = "Hello, world"; // <- Good...
   // string greeting("Hello, world"); // ... better
   
   cout << greeting <<endl; // Or '\n' instead of endl, if you prefer
   
   return 0;
}
bigdbag
Hello World's the starting program in every language but it's not helpful if you just give code like that. Comments help but you still need a lot of introduction of different parts of c++ code. And iostream.h is old. use #include<iostream>
Shirish
I think writing short codes that too like Hello World are much obsolete now,

If you ppl can come out with serious project source codes, then post here else there is no fun in watching all those noobiee's coding right on the forum..


Well there is no online complier to check your mistakes in that code
Related topics
Command and Conquer
Funny C variable
What can I do with C-Panel?
HELP ME in C++
Languages in c++
C++ TUTORIAL : INTRODUCTION TO C++
Beginners HTML Tutorial link
Complete Tutorial LINKS for every language
Learning C#
a game online
C or C++ books
VB.Net Or C#
C++ Tutorial
3 Websites To Get Started With Learning C++ Programming Lan
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.