Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Anybody know how read a text file and show your text in a variable?

Ex. one very simple text file with on text file ("Hello World" in hello.txt)

 

1. var1 = open the hello.txt

2. char *var = var1

 

Thanks

  • *Experts*
Posted

Are trying to do this using Managed Extensions? If yes then you can use the System::IO::StreamReader to read in the file and then assign it to a variable:

String* str; //string variable
System::IO::StreamReader* reads = new System::IO::StreamReader(S"hello.txt");
//new instance of StreamReader
str = reads->ReadToEnd(); //read the whole file using the ReadToEnd() method
reads->Close();

  • 4 weeks later...
Posted
Are trying to do this using Managed Extensions? If yes then you can use the System::IO::StreamReader to read in the file and then assign it to a variable:

String* str; //string variable
System::IO::StreamReader* reads = new System::IO::StreamReader(S"hello.txt");
//new instance of StreamReader
str = reads->ReadToEnd(); //read the whole file using the ReadToEnd() method
reads->Close();

christ this sort of code is kinda scaring me into not learning VC++
  • 7 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...