รายละเอียดนะครับ จะเป็นว่ามีอยู่ 1 file ที่เขียนจากภาษา
C เลยแล้ว save ไว้ ผมต้องการเขียนโปรแกรมจาก c หรือpascal ก็ได้เพื่ออ่านไฟล์นั้นแล้วบอกถึงจำนวน บรรทัดนะครับ ไม่ทราบว่าจะต้องมี function อะไรบ้างครับ
ขอความกรุณาด้วยนะครับ ขอบคุณครับ
รายละเอียดนะครับ จะเป็นว่ามีอยู่ 1 file ที่เขียนจากภาษา
C เลยแล้ว save ไว้ ผมต้องการเขียนโปรแกรมจาก c หรือpascal ก็ได้เพื่ออ่านไฟล์นั้นแล้วบอกถึงจำนวน บรรทัดนะครับ ไม่ทราบว่าจะต้องมี function อะไรบ้างครับ
ขอความกรุณาด้วยนะครับ ขอบคุณครับ
เขียนโดย VC++ นะครับ ถ้าต้องการอ่านไฟล์ก็แก้ตรง #define เองนะครับว่าไฟล์ของคุณชื่ออะไร
[src]
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
using namespace std;
#define openfile "test.txt"
int main(){
char buffer[255];
int counter=0;
ofstream outfile(openfile,ios:ut);
//ทำการเขียนข้อความ "test" ลงใน file
for (int i=0;i<20;++i)
{
outfile<<" "<<endl;
outfile<<"test"<<i<<endl;
}
outfile.close();
//เริ่มทำการเปิดไฟล์และนับบรรทัด
ifstream infile(openfile,ios::in);
while(!infile.eof())
{
infile.getline(buffer,100);
counter++;
}
cout<<"Number of line is "<<counter<<endl;
getch();
}
[/src]
Actions : (View-Readers)
There are no names to display.