I am trying to adjust the cursor position for a console project I am working on. This is taking right from the MSDN website (Microsoft's C++ database), but when I compile it says
"6 C:\Documents and Settings\j\My Documents\SimSTATS\test.cpp expected namespace-name before ';' token "
and highlights the line "using namespace System;"
Anyone help?
I've never used that before, I've only used "using namespace std;", in addition the above issue/question, can anyone briefly explain or point me to literature that could explain the different between namespace std and namespace System and when to use them?
Code:// This example demonstrates the // Console.CursorLeft and // Console.CursorTop properties, and the // Console.SetCursorPosition and // Console.Clear methods. using namespace System; int origRow; int origCol; void WriteAt( String^ s, int x, int y ) { try { Console::SetCursorPosition( origCol + x, origRow + y ); Console::Write( s ); } catch ( ArgumentOutOfRangeException^ e ) { Console::Clear(); Console::WriteLine( e->Message ); } } int main() { // Clear the screen, then save the top and left coordinates. Console::Clear(); origRow = Console::CursorTop; origCol = Console::CursorLeft; // Draw the left side of a 5x5 rectangle, from top to bottom. WriteAt( "+", 0, 0 ); WriteAt( "|", 0, 1 ); WriteAt( "|", 0, 2 ); WriteAt( "|", 0, 3 ); WriteAt( "+", 0, 4 ); // Draw the bottom side, from left to right. WriteAt( "-", 1, 4 ); // shortcut: WriteAt("---", 1, 4) WriteAt( "-", 2, 4 ); // ... WriteAt( "-", 3, 4 ); // ... WriteAt( "+", 4, 4 ); // Draw the right side, from bottom to top. WriteAt( "|", 4, 3 ); WriteAt( "|", 4, 2 ); WriteAt( "|", 4, 1 ); WriteAt( "+", 4, 0 ); // Draw the top side, from right to left. WriteAt( "-", 3, 0 ); // shortcut: WriteAt("---", 1, 0) WriteAt( "-", 2, 0 ); // ... WriteAt( "-", 1, 0 ); // ... // WriteAt( "All done!", 0, 6 ); Console::WriteLine(); } /* This example produces the following results: +---+ | | | | | | +---+ All done! */



LinkBack URL
About LinkBacks


