Sunday, August 2, 2009

How can I get Borland C++ to output a string to the terminal using 'cout'?

I'm trying to ouput a simple string "hello world" to the terminal. The program compiles and links with no errors, but when I run it there is no output. It's as if the standard output for 'cout' is not the terminal, but I don't know how to change it.

How can I get Borland C++ to output a string to the terminal using 'cout'?
I am not sure what program you tried, but here is one that should work on borlands compiler.





#include %26lt;iostream%26gt;





int main() {





std::cout%26lt;%26lt;"Hello, world!\n";


}





I have included the 'std::' namespace in front of the cout.





%26lt;Edit%26gt;


Are you running the program from the command line, or just clicking on the exe?


If clicking on the exe, a command line will pop up, then disappear after displaying hello world.


You need to run it from the command line.
Reply:#include %26lt;iostream%26gt;


//this could be used instead of


//prefixing each cin/cout with


//std::


using namespace std;





int main()


{


cout%26lt;%26lt;"my String"%26lt;%26lt;endl;


return 0;


}


No comments:

Post a Comment