hello world

Code:
#include <iostream>

using std::cout;
using std::endl;

int main()
{
     cout << "Hello, world!" << endl;
     return 0;
}

Might I suggest a good book, such as C++ How to Program by Deitel? :cheese:
 
if u have VS.NET installed or even just the sdk go search read the documentation (should be able to find a link in the start > programs > microsoft .NET Framework SDK folder ). Theres a hello world example in there somewhere.

Also it will depend on which language u intend to use.

Jamoe
 
isn't C++ How to Program by Deitel for vs 6.0 and such
should i get the one by them called Visual C++.NET: How to Program?
 
Originally posted by Quiddity
isn't C++ How to Program by Deitel for vs 6.0 and such
should i get the one by them called Visual C++.NET: How to Program?

If you want to learn how to program in C++ using all of the standard libraries, I would get the C++ How to Program book. And because you'll mainly be using standard libraries with that book, your [unmanaged] programs will compile in Visual Studio .NET. If you want to learn how to program in C++ using the Managed Extensions .NET offers, then I would suggest getting the book you mentioned. The direction you want to go is up to you.
 
Originally posted by Infernal-Shade
Code:
#include <iostream>

using std::cout;
using std::endl;

int main()
{
     cout << "Hello, world!" << endl;
     return 0;
}

Might I suggest a good book, such as C++ How to Program by Deitel? :cheese:

Oi! You'll get him into bad programming habits... he should type out std::cout and comment properly, like I had to :dork:

Code:
#include <iostream>

int main() // The function main() 
{
       std::cout << "Hello, world!" << "\n"; // cout (short for output, basically) prints these words to the screen in a black console box
       return 0; // since the function main doesn't return a value, it returns zero, or void
}


I hope that helps :)
 
dear god, over commenting hell. With something that simple at the most you need a comment on the line above and in most cases you dont need line by line commenting. If you was taught that then you've been taught bad habits yourself :)
 
To do a hello world in VS.net, open a new console project, and depending on your language (i'd use managed extensions for C++)

#using <mscorlib.dll>

using namespace System;

int main()
{
Console::WriteLine(S"Hello World!");
return 0;
}

Maybe I should wrap that main() in a class but....

EDIT: Oops, forgot the <> around mscorlib.dll....
 
Originally posted by bobvodka
dear god, over commenting hell. With something that simple at the most you need a comment on the line above and in most cases you dont need line by line commenting. If you was taught that then you've been taught bad habits yourself :)

Actually, I wrote all those comments to explain what everything is doing... :p I only comment on more complex things :p
 
#include <iostream>

using std::cout;
using std::endl;

int main()
{
cout << "Hello, world!" << endl;
return 0;
}


when i write this code i get an error in .net
the error says:

fatal error C1010: unexpected end of file while looking for precompiled header directive

whats this supposed to mean?
 
you've got pre-compiled headers turned on in the IDE, look in the project options (cant remember where off hand) to turn them off
 
wow. i just made a program like that. but not as complicated.

and yes, i compiled it.
 
You can write a hello world program with Microsoft Visual Studio .net in
- C++
- C
- VisualBasic
- C#
- J#
 
I was thinking someone made his first automatic forum spammer by the title. Oh well.
 
I was thinking someone made his first automatic forum spammer by the title. Oh well.
Funny... I thought the EXACT same thing...
 
hehe, i'm, not much farther than that.... this was most latest, and most advanced C++ program (though I could tear it up in TI-BASIC :) )

Code:
// a small c++ program
#include <iostream>
#include <string>

int main()
{ 
	// ask for name and then start framed greeting
	std::cout << " please enter your name. ";

	// read the name
	std::string name; // defines name
	std::cin >> name; //read into the name

	//build message
	const std::string greeting = "Hello, " + name + "!";

	//build 2nd and 4th lines
	const std::string spaces(greeting.size(), ' ');
	const std::string second = "* " + spaces + " *";

	//build 1st and 5th lines
	const std::string first(second.size(), '*');

	//write it all
	std::cout << std::endl;
	std::cout << first << std::endl;
	std::cout << second << std::endl;
	std::cout << "* " << greeting << " *" << std::endl;
	std::cout << second << std::endl;
	std::cout << first << std::endl;

	return 0;
 }
 
Why do you guys use that? It doesn't change anything, to my knowledge... I just write it like this:

Code:
#include <iostream.h>

void main()
{
  cout << "Hello world!\n"
       << "How are you doing today?\n"
       << "ME AM FINE!";
  //Using one cout statement to do all these quotes is fine...
  //But don't do too many!
}

Comments should only be used to help other programmers understand things that aren't readily apparent, or to help you remember things. So, don't do stuff like...

Code:
std::cout << "Hello World\n"; //"Hello World"
 
Sandman, 'void main()' is illegal C++

DON'T USE IT GUYS! Seriously, it won't compile.
 
int main() is ANSI compliant... i would suggest using that.
 
Why wouldn't void be ANSI compliant? Using a non-value-returning main is more efficient, and I believe that C++ doesn't care either way. There's no real exception handling done in simple console apps like hello world, so I don't think a value returning function is really necessary.

MrBadger, what compiler do you use?
 
Well, what i mean is that if use something that isn't ANSI compliant, then it's not guranteed to work in the future. void main() is legal, you can use it. but the industry uses int main(), and, i just learned in sociology that outcasts don't fare to well in society...

BTW.. i don't know why it isn't, just that it's not. :)
 
Of course it will work in the future. Why wouldn't it work in the future? Are you actually trying to get me to use int main instead of void main? It's not like void main is a cheap hack... really what's the big deal? :angel:
 
Dude, do what you want... I'm not trying to get you to do anything at all.. i am just telling you what ANSI says to do.
 
Sandman said:
Why do you guys use that? It doesn't change anything, to my knowledge... I just write it like this:

Code:
#include <iostream.h>

void main()
{
  cout << "Hello world!\n"
       << "How are you doing today?\n"
       << "ME AM FINE!";
  //Using one cout statement to do all these quotes is fine...
  //But don't do too many!
}

Coz that is wrong wrong wrong.
the headers such as <iosteam.h> are for old programs only.
Go out and learn proper C++, drop the .h and use namespaces how you are ment to.
 
Back
Top