| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 578 人关注过本帖
标题:谁可以帮我看下是哪错了? 是返回值错了吗?
只看楼主 加入收藏
tantan821
Rank: 2
等 级:论坛游民
帖 子:21
专家分:19
注 册:2010-5-15
收藏
 问题点数:0 回复次数:3 
谁可以帮我看下是哪错了? 是返回值错了吗?
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;

 
 
int filetovector(string filename,vector<string>& svec)
{
    ifstream infile(filename.c_str());
    if (!infile)
        return 1;


    string s;
    while (infile>>s)
    {
        svec.push_back(s);
    }
    infile.close();
    if (infile.eof())
    {
        return 4;
    }
    if (infile.bad())
    {
        return 2;
    }
    if (infile.fail())
    {
        return 3;
    }
}
 
int main()
{
    vector<string> svec;
    string filename,s;
   
    cout<<"Enter filename: "<<endl;
    cin>>filename;
    switch (filetovector(filename,svec))
    {
    case 1:
        cout<<"error: can not open file: "<<filename<<endl;
        return -1;
    case 2:
        cout<<"error: system laliure "<<endl;
        return -1;
    case 3:
        cout<<"error: read laliure "<<endl;
        return -1;
    }
    cout<<"vector:"<<endl;
    for (vector<string>::iterator iter=svec.begin();iter!=svec.end;--iter)
    {
        cout<<*iter<<endl;
    }
    return 0;
}
搜索更多相关主题的帖子: 返回值 
2010-08-13 11:22
jjg
Rank: 2
等 级:论坛游民
帖 子:67
专家分:42
注 册:2009-8-19
收藏
得分:0 
for (vector<string>::iterator iter=svec.begin();iter!=svec.end;--iter)
少了括号,end()
2010-08-13 12:04
jjg
Rank: 2
等 级:论坛游民
帖 子:67
专家分:42
注 册:2009-8-19
收藏
得分:0 
for (vector<string>::iterator iter=svec.begin();iter!=svec.end;--iter)
少了括号,end() ,还有就是,是iter++,
2010-08-13 12:09
pangding
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:北京
等 级:贵宾
威 望:94
帖 子:6784
专家分:16751
注 册:2008-12-20
收藏
得分:0 
小错误要注意!
2010-08-13 13:49
快速回复:谁可以帮我看下是哪错了? 是返回值错了吗?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019728 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved