(原創) 如何一行一行的讀取文字檔? (.NET) (C#) (C++/CLI) (C/C++)
C#
C++/CLI
/*
(C) OOMusou 2007 http://oomusou.cnblogs.com
Filename : TextReadLine.cs
Compiler : Visual Studio 2005 / C# 2.0
Description : Demo how to read text file line by line
Release : 07/28/2007 1.0
*/
using System;
using System.IO;
class Client {
static void Main() {
StreamReader stmRdr = new StreamReader("TextFile1.txt");
string line = stmRdr.ReadLine();
while(line != null) {
Console.WriteLine(line);
line = stmRdr.ReadLine();
}
}
}
(C) OOMusou 2007 http://oomusou.cnblogs.com
Filename : TextReadLine.cs
Compiler : Visual Studio 2005 / C# 2.0
Description : Demo how to read text file line by line
Release : 07/28/2007 1.0
*/
using System;
using System.IO;
class Client {
static void Main() {
StreamReader stmRdr = new StreamReader("TextFile1.txt");
string line = stmRdr.ReadLine();
while(line != null) {
Console.WriteLine(line);
line = stmRdr.ReadLine();
}
}
}
C++/CLI
/*
(C) OOMusou 2007 http://oomusou.cnblogs.com
Filename : TextReadLine.cpp
Compiler : Visual C++ 8.0 / C++/CLI
Description : Demo how to read text file line by line
Release : 07/28/2007 1.0
*/
#include "stdafx.h"
using namespace System;
using namespace System::IO;
int main() {
StreamReader^ stmRdr = gcnew StreamReader("TextFile1.txt");
String^ line = stmRdr->ReadLine();
while(line != nullptr) {
Console::WriteLine(line);
line = stmRdr->ReadLine();
}
}
(C) OOMusou 2007 http://oomusou.cnblogs.com
Filename : TextReadLine.cpp
Compiler : Visual C++ 8.0 / C++/CLI
Description : Demo how to read text file line by line
Release : 07/28/2007 1.0
*/
#include "stdafx.h"
using namespace System;
using namespace System::IO;
int main() {
StreamReader^ stmRdr = gcnew StreamReader("TextFile1.txt");
String^ line = stmRdr->ReadLine();
while(line != nullptr) {
Console::WriteLine(line);
line = stmRdr->ReadLine();
}
}