您的位置:程序门 -> c/c++ -> c++ 语言



stack的巨大烦恼,请高手帮忙


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


stack的巨大烦恼,请高手帮忙
发表于:2008-01-23 22:26:47 楼主
各位高人,我写了一下一段程序,想把文件数据读入到3个stack中:
    std::stack <std::string>   filenames;
    std::stack <short>   sx,sy;
    std::stack <float>   st;

    filenames.push("caldata0000.txt");
    filenames.push("caldata5000.txt");

    while(!filenames.empty())
    {
    std::ifstream   infile;

    infile.clear();

    infile.open((filenames.top()).c_str());

    filenames.pop();

    while(infile> > x> > y> > t)
    {
std::cout < <"hello";
sx.push(x);
std::cout < <x;
sy.push(y);
std::cout < <y;
st.push(t);
std::cout < <t;
    }
    infile.close();
    }
编译没有问题,不幸的是,运行程序后每当程序显示完hello,以后的动作就不再执行,5秒钟后程序窗口自动关闭。
按理说,我觉得程序没有什么大问题啊,所以请各位高手帮忙!多谢多谢!
发表于:2008-01-23 22:36:551楼 得分:0
c/c++ code
whiletrue) { infile>>x>>y>>t; if (infile.fail()) break; std::cout < <"hello"; sx.push(x); std::cout < <x; sy.push(y); std::cout < <y; st.push(t); std::cout < <t; }
发表于:2008-01-23 23:03:152楼 得分:0
回复1楼:
加入infile.fail()语句后情况与之前一样
问题应该不是出在读取文件数据的过程中,而是sx.push(x)的意外中断
但是这是为什么呢?搞不懂。。。
发表于:2008-01-23 23:11:573楼 得分:0
如果你的x,y,t都定义为short
文件里都是用空格或回车分隔开的数字的话
程序应该没嘛问题


快速检索

最新资讯
热门点击