| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 545 人关注过本帖
标题:关于文件写入的问题
只看楼主 加入收藏
qq1274371820
Rank: 1
等 级:新手上路
帖 子:149
专家分:0
注 册:2013-11-24
结帖率:75.86%
收藏
 问题点数:0 回复次数:2 
关于文件写入的问题

              怎么把下面的数据写入文件中?

              ORDER 是我定义的class ORDER

    ORDER order[10]={
    ORDER("flat shoes",1,20,400),
    ORDER("leather shoes",2,60,200),
    ORDER("military shoes",3,15,52),
    ORDER("footware shoes",4,25,600),
    ORDER("sports shoes",5,90,100),
    ORDER("travel shoes",6,80,200),
    ORDER("canvas shoes",7,75,150),
    ORDER("high heeled ",8,88,340)};
搜索更多相关主题的帖子: military leather travel sports shoes 
2014-06-16 22:07
qq1274371820
Rank: 1
等 级:新手上路
帖 子:149
专家分:0
注 册:2013-11-24
收藏
得分:0 


              额,我说仔细一点好了。
      
               就是下面这个代码,但是有错,要怎么改才能把O[9]里面的数据存入到chakan.txt文件中?




#include "stdafx.h"
#include"iostream"
#include"fstream"
#include"string"
#include<conio.h>  
using namespace std;
class ORDER
{
private:

    string PRONAME;
    int ID;
    float PRICE;
    int NUMBER;
public:
    ORDER(){};
    void chakan();
};
void ORDER::chakan()
{
    ORDER O[9];
    O[0].setdingdan("flat shoes",1,20,400);
    O[1].setdingdan("leather shoes",2,60,200);
    O[2].setdingdan("military shoes",3,15,52);
    O[3].setdingdan("footware shoes",4,25,600);
    O[4].setdingdan("sports shoes",5,90,100);
    O[5].setdingdan("travel shoes",6,80,200);
    O[6].setdingdan("canvas shoes",7,75,150);
    O[7].setdingdan("high heeled ",8,88,340);
    ofstream outfile;
    outfile.open("g:\\chakan.txt",ios::out);
    if(!outfile)
    {
        cerr<<"文件打开失败!"<<endl;
        exit(0);
    }
    for(int i=0;i<8;i++)
    {
        outfile<<O[i]<<endl;
    }
    outfile.close();
}
int main()
{
    ORDER j[8];
    ifstream infile;
    infile.open("g:\\chakan.txt",ios::in);
    if(!infile)
    {
         cerr<<"文件打开失败!"<<endl;
         exit(0);
    }
    for(int i=0;i<8;i++)
    {
           infile>>j[i];
           cout<<j[i]<<endl;
    }
    infile.close();
    return 0;
}


自定义人生。。。
2014-06-17 13:12
qq1274371820
Rank: 1
等 级:新手上路
帖 子:149
专家分:0
注 册:2013-11-24
收藏
得分:0 


               噢,public里面还有个函数:

           void ORDER::setdingdan(string proname,int id,float price,int number)
    {
        PRONAME=proname;
        ID=id;
        PRICE=price;
        NUMBER=number;
    }

自定义人生。。。
2014-06-17 13:54
快速回复:关于文件写入的问题
数据加载中...
 
   



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

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