954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

streamreader

I am working on visual studio 2008 what i want to do is read till the end of the file the code i am using is

StreamReader ^sr= gcnew StreamReader("example.txt");
				 String ^str;
				 while(sr->Read()!= 0)
				 {
					 str=sr->ReadLine();
					 textBox2->Text=sr->ReadLine();
					 MessageBox::Show(str);
				 }
					 sr->Close();

what could be used inside while condition that this will read till the end of the file

asadaziz
Newbie Poster
6 posts since Apr 2011
Reputation Points: 10
Solved Threads: 0
 

looking on msdn ( http://msdn.microsoft.com/en-us/library/system.io.streamreader.readtoend.aspx )
StreamReader has a ReadToEnd function.

is this what you were looking for?

MattyRobot
Junior Poster in Training
73 posts since Aug 2009
Reputation Points: 33
Solved Threads: 8
 

no the read to end function does not work with my code i want a way in which my program can read a file till the end

thanks for the reply by the way :)

asadaziz
Newbie Poster
6 posts since Apr 2011
Reputation Points: 10
Solved Threads: 0
 

you mean you want the output tokenized into lines?

MattyRobot
Junior Poster in Training
73 posts since Aug 2009
Reputation Points: 33
Solved Threads: 8
 

yup the read to end function reads all the file and stores it in a single string i got it but i wanted the output tokened in lines

asadaziz
Newbie Poster
6 posts since Apr 2011
Reputation Points: 10
Solved Threads: 0
 

looking on msdn again. http://msdn.microsoft.com/en-us/library/aa904305(v=vs.71).aspx

you could read the whole stream into a string using ReadToEnd then use String.Split and pass '\n' to it ('\n' == New Line)

MattyRobot
Junior Poster in Training
73 posts since Aug 2009
Reputation Points: 33
Solved Threads: 8
 

thank u very much was of great help :)

asadaziz
Newbie Poster
6 posts since Apr 2011
Reputation Points: 10
Solved Threads: 0
 

mark as solved :) + glad i could help

MattyRobot
Junior Poster in Training
73 posts since Aug 2009
Reputation Points: 33
Solved Threads: 8
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: