C++_读入很多行字符串到字符串指针数组、或者到字符串数组中

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main(){
    ifstream ifs("dict.txt");
    string *dict[5000];
    int i=0;
    while(i<5000){
        dict[i]=new string();
        getline(ifs,*dict[i]);
        i++;
    }
    ifs.out;
    return 0;
}

 上面是读入到字符串指针数组中,下面是读入到字符串数组中。

#include<iostream>
#include<fstream>
#include<string>
using namespace std;
int main(){

    ifstream ifs("dict.txt");
    char *dict[15];
    int i=0;
    while(i<5000){
        dict[i]=(char *)malloc(60);
        ifs>>dict[i];
        i++;
    }
    ifs.out;
    return 0;
}

 

posted @ 2013-07-24 08:56  开心成长  阅读(407)  评论(0编辑  收藏  举报