Does not recognize namespace

Dear everyone, I am trying to compile the following sample code, but it keeps saying that it does not recognize System as a namespace. I have tried some other program with other namespace, and it works OK..

Please help!

thanks for your kind attention



using namespace System;
using namespace System::IO;

int main()
{
String^ fileName = "Testing.dat";
sprintf()
// Create random data to write to the file.
array<Byte>^dataArray = gcnew array<Byte>(100000);
(gcnew Random)->NextBytes( dataArray );
FileStream^ fileStream = gcnew FileStream( fileName,FileMode::Create );
try
{

// Write the data to the file, byte by byte.
for ( int i = 0; i < dataArray->Length; i++ )
{
fileStream->WriteByte( dataArray[ i ] );

}

// Set the stream position to the beginning of the file.
fileStream->Seek( 0, SeekOrigin::Begin );

// Read and verify the data.
for ( int i = 0; i < fileStream->Length; i++ )
{
if ( dataArray[ i ] != fileStream->ReadByte() )
{
Console::WriteLine( "Error writing data." );
return -1;
}

}
Console::WriteLine( "The data was written to {0} "
"and verified.", fileStream->Name );
}
finally
{
fileStream->Close();
}

}


Is this C++ or C#?
Maybe You are missing some #include <...> because without include there is no to load namespace.
closed account (z05DSL3A)
The code is C++/CLI is the project a CLR one? If the project is a standard C++ one then it will not understand C++/CLI or any of the .net framework namespaces etc.
Last edited on
use /clr when compiling or one of the flavors: /clr:pure

the prototype for main should look like this:

int main(array<System::String ^> ^args) to be compatible with C# etc.

hth

Topic archived. No new replies allowed.