Click to See Complete Forum and Search --> : Read from file
usingnamespace
March 8th, 2008, 07:24 PM
I managed to write text from textbox to file with StreamWriter method. Now I would need to read that text from file back into textbox. I wanted to use StreamReader method, but i couldn't find any helpful VC++ information (only Visual Basic and C#). Could anyone please post some example, also if there is any better method?
cilu
March 9th, 2008, 06:41 AM
What language are you using? C++, C++/CLI? In C++ see std::ifstream from <fstream>. In MFC see CFile or CStdioFile (for text files).
usingnamespace
March 9th, 2008, 07:58 AM
I am using VC++ CLR WinForm.
cilu
March 9th, 2008, 08:07 AM
Well, is that C++/CLI or managed C++? VC++ 2008? 2005? 2003?
Anyhow, it's the same as in C#. The way you read it in C# you do it in C++/CLI. There are the same classes, just the syntax is different.
cilu
March 9th, 2008, 08:08 AM
[ redirected ]
usingnamespace
March 9th, 2008, 08:32 AM
I am using VC++ Visual Studio 2005. I have been trying that for the last few days, with no success. Could you please post an example? I would need to read line by line. Lets say I write text from textBox1 to line 1, and text from textBox2 to line 2 and I would need to read it back into the same textboxes.
usingnamespace
March 9th, 2008, 04:40 PM
If I use:
StreamReader^ sr = gcnew StreamReader("File.txt");
String^ line;
line = sr->ReadLine();
textBox1->Text=(line);
I get first line of file.
If i use loop i get last line of file.
I want to read specific lines, but ReadLine() doesn't accept any arguments.
kinglu
March 10th, 2008, 05:10 AM
thank your reply, ciLu.
It helps a lot.
usingnamespace
March 11th, 2008, 05:08 PM
No one knows?
codeguru.com
Copyright 2007 Jupitermedia Corporation All Rights Reserved.