| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 670 人关注过本帖
标题:这个程序哪里有错啊
只看楼主 加入收藏
jjg
Rank: 2
等 级:论坛游民
帖 子:67
专家分:42
注 册:2009-8-19
结帖率:46.15%
收藏
已结贴  问题点数:20 回复次数:7 
这个程序哪里有错啊
#include <iostream>
#include <fstream>
#include <string>

#include <list>
using namespace std;
main()
{
    ofstream fileone("file.txt");
    string a("file.txt");
    fileone<<"huanyinglaijinda"<<endl;
    ifstream infile(a.c_str());
    list<string>lst;
    string s;
    while(infile>>s)
        lst.push_back(s);
    infile.close();
    lst.sort();
    list<string>::iterator ilst;
    while(!ilst->end())
    {
        cout<<*ilst;
    }
}

我对文件的操作和STL都不熟悉,大家指点一下
搜索更多相关主题的帖子: std include 
2010-06-01 22:39
Isilendil
Rank: 2
来 自:广东省广州市
等 级:论坛游民
帖 子:13
专家分:42
注 册:2010-6-2
收藏
得分:5 
#include <iostream>
#include <fstream>
#include <string>

#include <list>
using namespace std;
int main()
{
    ofstream fileone("file.txt");
    string a("file.txt");
    fileone<<"huanyinglaijinda"<<endl;
    ifstream infile(a.c_str());
    list<string>lst;
    string s;
    while(infile>>s)
        lst.push_back(s);
    infile.close();
    lst.sort();
    list<string>::iterator ilst = lst.begin();
    while(ilst != lst.end())
    {
        cout<<*ilst;
        ++ ilst;
    }
    return 0;
}

能跑了,但是不知道这段程序是要干什么,list里只有一个string,却还要排序,遍历输出
2010-06-02 00:35
lijm1989
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:珠海
等 级:贵宾
威 望:12
帖 子:675
专家分:2844
注 册:2009-10-14
收藏
得分:5 
程序代码:
#include <iostream>
#include <fstream>
#include <string>

#include <list>
using namespace std;
int main()
{
    ofstream fileone("file.txt");
    string a("file.txt");
    fileone<<"huan ying lai jin da"<<endl;
    ifstream infile(a.c_str());
    list<string>lst;
    string s;
    while(infile>>s)
        lst.push_back(s);
    infile.close();
    lst.sort();
    list<string>::iterator ilst = lst.begin();
    while(ilst != lst.end())
    {
        cout<<*ilst<<endl;
        ++ ilst;
    }
    return 0;
}
难道是这样?LZ最好把代码的目的和现在代码怎么错了说一下。。。
2010-06-02 10:19
gaoce227
Rank: 4
来 自:山东
等 级:业余侠客
帖 子:134
专家分:218
注 册:2008-4-5
收藏
得分:0 
我只知道lz使用的不是标准的C++。
2010-06-02 11:29
jjg
Rank: 2
等 级:论坛游民
帖 子:67
专家分:42
注 册:2009-8-19
收藏
得分:0 
回复 2楼 Isilendil
我要使文件中的字符排序,该怎么写呢
2010-06-02 17:21
shinelin09
Rank: 2
来 自:中国
等 级:论坛游民
帖 子:9
专家分:20
注 册:2010-5-17
收藏
得分:0 
   我也正对这个发愁呢
2010-06-02 18:30
lijm1989
Rank: 11Rank: 11Rank: 11Rank: 11
来 自:珠海
等 级:贵宾
威 望:12
帖 子:675
专家分:2844
注 册:2009-10-14
收藏
得分:10 
字符??
程序代码:
#include <iostream>
#include <fstream>
#include <string>

#include <list>
using namespace std;
int main()
{
    ofstream fileone("file1.txt");
    string a("file1.txt");
    fileone<<"huanyinglaijinda"<<endl;
    ifstream infile(a.c_str());
    list<char>lst;
    char s;
    while(infile>>s)
        lst.push_back(s);
    infile.close();
    lst.sort();
    list<char>::iterator ilst = lst.begin();
    while(ilst != lst.end())
    {
        cout<<*ilst;
        ++ ilst;
    }
    return 0;
}
2010-06-02 20:55
jjg
Rank: 2
等 级:论坛游民
帖 子:67
专家分:42
注 册:2009-8-19
收藏
得分:0 
回复 7楼 lijm1989
我咋就那么傻呢
2010-06-03 19:57
快速回复:这个程序哪里有错啊
数据加载中...
 
   



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

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