注册 登录
编程论坛 C++教室

不懂求教

hhitjsj021 发布于 2008-08-15 10:05, 794 次点击
程序代码:
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<algorithm>
#include<stdlib.h>
using namespace std;

vector<string> *tvec()
{
    string filename;
    cout<<"please enter filename:"<<endl;
    cin>>filename;

    //open file
    ifstream infile(filename.c_str(),ios::in);

    //if(!filename)
    if(!infile.is_open())
    {
        cout<<"unable to open the file "<<filename;
        exit(-1);
    }   
    else
        cout<<"\n";

    vector<string> *lines_of_text=  new vector<string>;
    string textline;
    typedef pair<string::size_type,int> stats;
    stats maxline;
    int numline=0;

    while (getline(infile,textline,'\n'))
    {
        cout<<"lineread:"<<textline<<'\n';
        if(maxline.first<textline.size())   //这里的maxline.first是什么意思啊?不明白
        {
            maxline.first=textline.size();
            maxline.second=numline;
        }
        lines_of_text->push_back(textline);
        ++numline;
    }
    return lines_of_text;
}

int main()
{
    vector<string>* evec;
    evec=tvec();
    return 0;
   
}
3 回复
#2
xxp272008-08-15 10:33
因为你这里用到了pair类型
typedef pair<string::size_type,int> stats;

pair类型包含两个元素,第一个就成为first,第二个就称为second
#3
HERO剧终2008-08-15 10:39
  真痛苦,看不太懂;
        好想学C++啊
#4
hhitjsj0212008-08-15 10:54
感谢,豁然开朗
1