OK

Started by
13 comments, last by cybersniper 21 years, 2 months ago
quote:Original post by moose_2006
Try this:
--------------------------------------------
#include <iostream>
namespace std;

int main()
{
cout << "Hello world!" << endl;

return 0;
}
--------------------------------------------

You want using namespace std; there.

Either of these should work:

  // Number 1:#include <iostream>int main(){    std::cout << "Hello, world!" << std::endl;    return 0;}// Number 2:#include <iostream>using namespace std;int main(){    cout << "Hello, world!" << endl;    return 0;}  

If you are just starting to learn C++, cybersniper, then I would recommend buying a good book.

[ Google || Start Here || ACCU || MSDN || STL || GameCoding || BarrysWorld || E-Mail Me ]
[ Google || Start Here || ACCU || STL || Boost || MSDN || GotW || CUJ || MSVC++ Library Fixes || BarrysWorld || [email=lektrix@barrysworld.com]E-Mail Me[/email] ]
Advertisement
no you should do

    #include <iostream>int main(){    cout.write("Hello, World!", 13) << endl;    return 0;}    


EDIT: fixed arglist

[edited by - sneftel on February 10, 2003 4:34:45 AM]
quote:Original post by Sneftel
. . .


quote:
ostream_type& write(const char_type* s, streamsize n );

Obtains characters to insert from successive locations of an array whose first element is designated by s. Characters are inserted until either of the following occurs:

n characters are inserted
Inserting in the output sequence fails

In the second case the function calls the basic_ios member function setstate(badbit). The function returns *this.


If your example actually works, I don't imagine it is very portable.

[edited by - smart_idiot on February 10, 2003 4:28:39 AM]
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
You''re absolutely right; it''s been a while since I had much use for ostream::write().

Don''t listen to me. I''ve had too much coffee.
Ah, well i see two potential problems. Problem A: You didn''t create the right type of project and it''s not compiling/linking. You have to use console wizard to create a console mode application.

Potential problem 2. The program is running properly, but it runs so quickly that the Hello world disappears instantly when the program is done. To stop that, just do something like

int a;
cin >> a;

This will keep everything on screen until the program terminates.
*Only in darkness can one truely shine*

This topic is closed to new replies.

Advertisement