views:

311

answers:

5

Possible Duplicates:
Changing c++ output without changing the main() function
How to assign a method's output to a textbox value without code behind

How to write hello world without modifying main function? Thanks

int main(){return 0;}
+8  A: 

Just add this code to a .cpp file somewhere.

class Hack {
  Hack() { cout << "Hello World"; }
} hackInstance;
JaredPar
+2  A: 

Use the preprocessor to #define an expansion for return to print hello world, then return.

Dave Bauman
+1  A: 

I'm assuming there's a creative use of #define preprocessor statements that can make this work.

Stefan Kendall
+8  A: 
#include<iostream>

int hello() {
    cout<<"Hello World"<<endl;
}

static int foo = hello();

int main(){return 0;}
Nathaniel Flath
@bbaja42-don't forget, only way if you can see the output if you add a system("pause"); in the hello function after the cout statement, but this works
TStamper
Or run it in console, since it is in fact a console application. system("pause") is not standard.
GMan
A: 

Yes, strange.

Joshua Louden