C/C++读取文件

C++读文件

#include <iostream>
#include <fstream>
using namespace std;
int main(){
/*
        ifstream ifs("./dict.txt");
        string s;
        while(ifs>>s){
                cout<<s.c_str();
        }
*/


        ifstream ifs("./dict.txt");
        string s;
        while(getline(ifs,s)){
                cout<<s<<endl;
        }
        return 0;
}

C读取文件

#include "stdio.h"
int main(int argc,char *argv[]){
        FILE *fp;
        fp=fopen("dict.txt","r");
        char buffer[1024];
        char *pbuf;
        while((pbuf=fgets(buffer,100,fp))!=NULL){
                printf("%s",buffer);
        }
        //printf("xxxxxxxxxxxx\n");
        return 0;
}

你可能感兴趣的:(C/C++读取文件)