qq_38402746
qq_38402746
2017-06-16 01:17

c++ 文件输入输出流 无法输入 代码如下(真心求急救)

  • c++

void Node::InputMule()
{
pHead = new NODE[sizeof (Node)];
if(NULL == pHead)
{
cout << "分配动态内存失败" << endl;
exit(0);
}

    PNODE pTail = pHead;
    pTail -> pNext = NULL;

    int number; //  头数
    char name[30];
    int id;
    int age;
    double weight;
    double thingweight;
    char color[30];

    cout << "请输入头数" << endl;
    cin >> number;
    cout << "输入好了" << endl;

    ifstream infile("infile.txt",ios::in);

    for(int i = 0 ; i < number ;i ++){
            PNODE pNew = new NODE[sizeof(NODE)];
            if(NULL == pNew){
                    cout << "分配动态内存失败" << endl;
                    exit(0);
            }


    char s[10];
    if(!infile){
            ofstream outfile("outfile.txt");
            while(infile.peek() == EOF){
                            cout << "love" << endl;
                            infile  >> name ;
                            cout << "me" << endl;
                                    outfile<< name << "*********************************" << "  " << '\n' <<'\t' << endl;
                            infile.read(s,sizeof(s) - 1);
                                    outfile << '\t' <<"骡的名字" << '\t' << name << endl;
                            infile.getline(s,sizeof(s) - 1);
                                    outfile << '\t' <<"骡的年龄" << '\t' << age << endl;
                            infile.getline(s,sizeof(s) - 1);
                                    outfile << '\t' << "骡的体重" << '\t'<< weight << endl;
                            infile.getline(s,sizeof(s) - 1);
                                    outfile << '\t' << "骡的负重" << '\t'<< thingweight << endl;
                                                                            infile.get(s,sizeof(s) - 1);
                                    outfile << '\t' << "骡的颜色" << '\t' << color << endl;
                    }

                    outfile.close();
    }

            pNew -> mu.SetInfo(name,age);
            pNew -> mu.SetId(id);
            pNew -> mu.SetWeight(weight);
            pNew -> mu.SetColor(color);
            pNew -> mu.SumWeight(weight,thingweight);
            pNew -> mu.SetThingweight(thingweight);

            pTail -> pNext = pNew;
            pTail = pNew;
            pTail -> pNext = NULL;

    }

    infile.close();

    cout << "已经成功的向程序中输入了" << number << "头骡信息" << endl;

}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答