G
Guest
Excuse me if you consider this a cross post, however, it was originally destined for this group not the vc.atl group, but somehow it went there instead of here! (obviously it was something I did, but hey ho) ... now back to the problem in hand
I've made what I consider to be the simplest of applications, but it won't work. This is my code
#using <mscorlib.dll>
#include <tchar.h>
using namespace System;
int _tmain(void)
{
String* args[] = Environment::GetCommandLineArgs();
try
{
try
{
Console::WriteLine(String::Format(S"You supplied {0} arguments", __box(args->Length)));
}
catch(Exception* e)
{
Console::WriteLine(S"\nERROR WITH args\n---------------\n");
Console::WriteLine(e->Message);
Console::WriteLine(e->TargetSite);
Console::WriteLine(e->StackTrace);
}
if(!args)
Console::WriteLine(S"\nYou didn't supply any arguments\nVielleicht das nachster zeit!\n\n");
else if(args->Length > 1)
Console::WriteLine(S"\nYou supplied too many arguments\nVielleicht das nachster zeit!\n\n");
else
{
int counter = Int32:arse(args[0]);
for(int i = 0; i < counter; i++)
{
Console::WriteLine(S"I am a programmer.");
}
Console::WriteLine(S"");
}
}
catch(Exception* e)
{
Console::WriteLine(S"\nERROR\n-----\n");
Console::WriteLine(e->Message);
Console::WriteLine(e->TargetSite);
Console::WriteLine(e->StackTrace);
}
return 0;
}
and this is the result of running the application:
W:\C++\MTest\Debug>MTest
ERROR WITH args
---------------
Object reference not set to an instance of an object.
Int32 main()
at main() in w:\c++\mtest\mtest.cpp:line 20
ERROR
-----
Input string was not in a correct format.
Int32 ParseInt32(System.String, System.Globalization.NumberStyles, System.Globalization.Nu
mberFormatInfo)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Int32.Parse(String s)
at main() in w:\c++\mtest\mtest.cpp:line 36
W:\C++\MTest\Debug>MTest 2
ERROR WITH args
---------------
Object reference not set to an instance of an object.
Int32 main()
at main() in w:\c++\mtest\mtest.cpp:line 20
You supplied too many arguments
Vielleicht das nachster zeit!
I've made what I consider to be the simplest of applications, but it won't work. This is my code
#using <mscorlib.dll>
#include <tchar.h>
using namespace System;
int _tmain(void)
{
String* args[] = Environment::GetCommandLineArgs();
try
{
try
{
Console::WriteLine(String::Format(S"You supplied {0} arguments", __box(args->Length)));
}
catch(Exception* e)
{
Console::WriteLine(S"\nERROR WITH args\n---------------\n");
Console::WriteLine(e->Message);
Console::WriteLine(e->TargetSite);
Console::WriteLine(e->StackTrace);
}
if(!args)
Console::WriteLine(S"\nYou didn't supply any arguments\nVielleicht das nachster zeit!\n\n");
else if(args->Length > 1)
Console::WriteLine(S"\nYou supplied too many arguments\nVielleicht das nachster zeit!\n\n");
else
{
int counter = Int32:arse(args[0]);
for(int i = 0; i < counter; i++)
{
Console::WriteLine(S"I am a programmer.");
}
Console::WriteLine(S"");
}
}
catch(Exception* e)
{
Console::WriteLine(S"\nERROR\n-----\n");
Console::WriteLine(e->Message);
Console::WriteLine(e->TargetSite);
Console::WriteLine(e->StackTrace);
}
return 0;
}
and this is the result of running the application:
W:\C++\MTest\Debug>MTest
ERROR WITH args
---------------
Object reference not set to an instance of an object.
Int32 main()
at main() in w:\c++\mtest\mtest.cpp:line 20
ERROR
-----
Input string was not in a correct format.
Int32 ParseInt32(System.String, System.Globalization.NumberStyles, System.Globalization.Nu
mberFormatInfo)
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
at System.Int32.Parse(String s)
at main() in w:\c++\mtest\mtest.cpp:line 36
W:\C++\MTest\Debug>MTest 2
ERROR WITH args
---------------
Object reference not set to an instance of an object.
Int32 main()
at main() in w:\c++\mtest\mtest.cpp:line 20
You supplied too many arguments
Vielleicht das nachster zeit!