Hola hice esta declaracion y me dice que el parametro S necesita un
parametro /clr:oldstyle, o algo asi.. pero si lo pongo me detecta errores en
el .h en la linea de declaracion de la clase, en donde hay un public. El
caso es el siguiente:
String* path=S"hola"; // detecta error porque?
FileStream* fs = File::Open(path, FileMode::Open, FileAccess::Read,
FileShare::None); //tampoco entiende el *
El codigo lo saque de:
http://msdn.microsoft.com/library/d...ntopic.asp
Y es este:
#using <mscorlib.dll>
using namespace System;
using namespace System::IO;
using namespace System::Text;
int main() {
String* path = S"c:\\temp\\MyTest.txt";
// Delete the file if it exists.
if (!File::Exists(path)) {
// Create the file.
FileStream* fs = File::Create(path);
try {
Byte info[] = (new UTF8Encoding(true))->GetBytes(S"This is some
text in the file.");
// Add some information to the file.
fs->Write(info, 0, info->Length);
} __finally {
if (fs) __try_cast<IDisposable*>(fs)->Dispose();
}
}
// Open the stream and read it back.
FileStream* fs = File::Open(path, FileMode::Open, FileAccess::Read,
FileShare::None);
try {
Byte b[] = new Byte[1024];
UTF8Encoding* temp = new UTF8Encoding(true);
while (fs->Read(b,0,b->Length) > 0) {
Console::WriteLine(temp->GetString(b));
}
try {
// Try to get another handle to the same file.
FileStream* fs2 = File::Open(path, FileMode::Open);
try {
// Do some task here.
} __finally {
if (fs2) __try_cast<IDisposable*>(fs2)->Dispose();
}
} catch (Exception* e) {
Console::Write(S"Opening the file twice is disallowed.");
Console::WriteLine(S", as expected: {0}", e);
}
} __finally {
if (fs) __try_cast<IDisposable*>(fs)->Dispose();
}
}
Leer las respuestas