Mysterious variable assignment

Hello. As the title suggests, I'm having this weird bug where an int var is being assigned a number that I didn't specify. It's on a Maze game project I'm making for the console.

Specs:
OS: Windows 7 Home Premium 64-bit
Compiler: Dev C++ ver 4.9.9.2

Problem Specifics:

My project has 5 files: 3 sources, 2 headers.
The main.cpp of my project:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <iostream>
#include <sstream>
#include <fstream>
#include <vector>
#include <conio.h>
#include <time.h>
#include "_functions.h"
#include "_classes.h"

using namespace std;

main()
{
      room Room0("resources/maps/map0/room 0.txt");
      getch();
}


The bug occurs in the constructor of the "room" class.
First, the header file with the class definition:
1
2
3
4
5
6
7
8
9
10
class room
{
      public:
             room(string file);
      
      private:
              vector<string> event;
              string name, directions;
              char directionbuf[4];
};


Now the constructor:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
room::room(string file)
{
            name=readFile(file, NODISPLAY, 1);
            string charbuf1=readFile(file, NODISPLAY, 2), charbuf2;
            int hold;
            
            for (int i=0;i<5;i++)
            {
                  for (int count=0;count<3;count++);
                  {
                      charbuf2+=charbuf1[0];
                      charbuf1.erase(0,1);
                  }
                  charbuf1.erase(0, 1);
                  
                  hold=strint_conv(charbuf2);
                  directionbuf[i]=(char)hold;
            }
            
            cout << "If everything worked, the next cout should give arrows.\n\n";
            nogetch();
            
            for (int i=0;i<5;i++) cout << directionbuf[i] << endl;
            nogetch();
}


(nogetch() is a function I use to simply pause the program without returning anything from getch(). If you are wondering about it, here's the function definition.)
void nogetch() {getch();}

What I'm trying to accomplish is, in order for the player to know which direction he/she can take, I'll print arrows onto the screen. I happen to know that when I print a char with the value of 24-27, arrows are printed to the screen. Now here's what's going on:
1
2
3
4
5
for (int count=0;count<3;count++);
                  {
                      charbuf2+=charbuf1[0];
                      charbuf1.erase(0,1);
                  }


At this point, the var "count" is being initialized with the value 0, but when I was executing this section of code with my debugger, it said that after the line where the for loop begain, the "count" variable had the value 2.

The debugger isn't spewing errors, and the code compiles fine, so I'm not sure as to why this is happening. If I am missing something obvious, go easy on me; we all make errors :)



I'm fairly new to posting on these forums, so constructive criticism is greatly valued.
1
2
3
4
5
for (int count=0;count<3;count++);
                  {
                      charbuf2+=charbuf1[0];
                      charbuf1.erase(0,1);
                  }


the first line ends with a semicolon, resulting in an empty loop.
Topic archived. No new replies allowed.