有一些同事是做Java 的有人问我怎么用C语言
//============================================================================ // Name : HelloWorld.cpp // Author : liuqing // Version : // Copyright : Your copyright notice // Description : C语言操作文件 //============================================================================ #include <iostream> #include <stdio.h> #include <stdlib.h> using namespace std; int main() { //定义文件指针 FILE *fp; //定义输出字符 char ch; cout << "Reading file...." << endl; //打开文件 if ( ((fp = fopen("f:\\aa.txt","rt")) == NULL)) { cout << "error open file f:\\aa.txt"; } else { //根据文件指针操作文件 while ( (ch = getc(fp)) != EOF) { putchar(ch); } } //关闭文件 fclose(fp); return 0; }