读文件 处理字符串, 作者未知

来源:互联网 发布:河南云和数据怎么样 编辑:程序博客网 时间:2024/04/24 12:01


#include <conio.h>
#include <stdio.h>
#include    <vector>  
#include    <fstream>  
#include    <string>  
#include    <iostream>  
#include    <cstdlib>  
  
using   namespace   std; 
void anyliststr();
  char Buf[101]={0};  //输入文件名
 char outputname[101]={0};//输出文件名
 int k=0;// 统计数字
// goto again;
int   main() 
{ //  输入文件名
again:
 memset(Buf,0,sizeof(Buf));
 memset(outputname,0,sizeof(outputname));
 k=0;
    char Buf[101]={0};//使用前,请先先初始话,即使没赋上值,也不至于乱码
    cout << "输入文件名:";
    cin>>Buf;
    cout << "输出文件名:";
    cin>>outputname;
    ifstream   ifile(Buf); 
    vector <string>    str; 
    string   line; 
  
    while   (!ifile.eof()) 
    { 
        getline(ifile,   line);      //读取一行 
        //cout << "line:    " <<line <<endl; 
        str.push_back(line);      //插入到   vector 
    } 
    cout <<endl; 
  
    int   len=str.size(),   i; 
    for(i=0;   i <len;   i++) 
        cout << "in   vector:    " <<str[i] <<endl;      //数组方式访问也许更熟悉一些    
    return   0; 

  

原创粉丝点击