HanuSoftware
asked on
readig a .txt file
how to read .txt file that is in a given drive (for example the file path is "c:\raj.txt") in VC++.net language.
Please give me the exact code that could run in VC++.net Environment.
Please give me the exact code that could run in VC++.net Environment.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Wow, I must be asleep this morning, that's C#, not C++.
Here's what you want: http://support.microsoft.com/kb/307384/EN-US/
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Points to rstaveley, but I would say that wouldn't I? ;-)
using System;
using System.IO;
class Test
{
public static void Main()
{
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader("c:\\raj.txt"
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null)
{
Console.WriteLine(line);
}
}
}
catch (Exception e)
{
// Let the user know what went wrong.
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Messag
}
}
}