Thread: more questions!!

  1. #1
    A Banana Yoshi's Avatar
    Join Date
    Oct 2001
    Posts
    859

    more questions!!

    since my teacher is being... dumb... I thought i ask here

    Code:
       while(pickenemy != picking){
          infile >> enemy_name;
          picking ++;
       }
       fighting = true;
       infile >> enemy[LVL];
       infile >> enemy[STR];
       infile >> enemy[AGL];
       infile >> enemy[INT];
       infile >> enemy[MP_MAX];
       infile >> enemy[HP_MAX];
       infile >> enemy[LM];
    
       enemy[MP_CRT] = enemy[MP_MAX];
       enemy[HP_CRT] = enemy[HP_MAX];
    Wood_Pecker
    2
    9
    13
    7
    13
    10
    5

    do infile automatically go to the next line when it reads the integers? Why did it displays 0x00000000 when i put a cout in front of infile >> enemy[LVL];?
    Yoshi

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Since >> returns a confirmation code of the read operation, not the data.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    You can, and should, actually use the return from the >> operation to make sure that you are still reading the file. If an error occurs (such as the EOF) you can tell the player that their game file was erased or corrupted.

  4. #4
    Every time you use infile it goes to the next line... well that is in my experiance and thats how i do it in my game

    Code:
    cout << "\n\nWhat is your name: (type exit to go back to the menu): ";
      cin >> filename;
      if(strcmp(filename,"exit")!=0) 
      {
      infile.open(filename);
      if (!infile)
       {
        clrscr();
        cout << "\n\nThat is not a valid character. Please try again.\n\n";
        Sleep(2000);
        return main();
       } 
       else if (infile.good())
       {
    
    
      infile >> user.name;
      infile >> user.nextskill;
      infile >> skill.skillneed;
      infile >> user.skill;
      infile >> user.money;
      infile >> user.hp;
      infile >> user.armor;
      infile >> user.health;
      infile >> user.maxdam;
      infile >> user.mindam;
      infile >> user.skillpoints;
      infile >> lvl.setone;
      infile >> lvl.settwo;
      infile >> lvl.setthree;
      infile >> lvl.setfour;
      infile >> lvl.setfive;
      infile >> it.amulate;
      infile >> it.fpotion;
      infile >> it.glow;
      infile >> it.potion;
      infile >> it.ring;
      infile >> it.shield;
      infile >> it.sword;
    Dev C++
    Win XP/2k/98

    I DO NOT TAKE CLASSES I DONT GET HOMEWORK THIS IS NOT A HOMEWORK QUESTION!!!

    He's lean he's keen... He's the spank machine!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions....so many questions about random numbers....
    By face_master in forum C++ Programming
    Replies: 2
    Last Post: 07-30-2009, 08:47 AM
  2. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  3. Several Questions, main one is about protected memory
    By Tron 9000 in forum C Programming
    Replies: 3
    Last Post: 06-02-2005, 07:42 AM
  4. Trivial questions - what to do?
    By Aerie in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 12-26-2004, 09:44 AM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM