Help needed with code

i am trying to make a text based level editor in c++
and i thought i would save time by instead or writing
a lot of if statements i would use a for loop when i run
it it dose nothing so could someone show me whats wrong with
this code thanks in advance.


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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
  void interpter()// translates code into a map needs work!!!
{
     string value;
     string Map_code [10];
     ifstream Map_data("Map_data.data");
     cout <<"Reading file...";
     Map_data >> Map_code[0] >> Map_code[1] >> Map_code[2] >> Map_code[3] >> Map_code[4] >> Map_code[5] >> Map_code[6] >> Map_code[7] >> Map_code[8] >> Map_code[9];
     cout << Map_code[0] << Map_code[1] << Map_code[2] << Map_code[3] << Map_code[4] << Map_code[5] << Map_code[6] << Map_code[7] << Map_code[8] << Map_code[9];
     for (int i = 0; i < 10;)
     {
         if (Map_code[i] == "0")
         {
                         cout <<" ";
                         }
         else if (Map_code[i] == "1")
         {
                         cout <<"\n";
                         }
         else if (Map_code[i] == "2")
         {
                         cout <<"#####\n";
                         cout <<"#####\n";
                         cout <<"#####\n";
                         cout <<"#####\n";
                         cout <<"  ¦\n";
                         cout <<"  ¦\n";
                         cout <<"  ¦\n";
                         }
         else if (Map_code[i] == "3")
         {
                         cout <<" ________\n";
                         cout <<"| #  #  |\n";
                         cout <<"|       |\n";
                         cout <<"| #  #  |\n";
                         cout <<"|       |\n";
                         cout <<"|  {}   |\n";
                         cout <<"-_______-\n";
                         }
         else
         {
             //do nothing
             cout<<"";
             }
         i++;
         }
     getline(cin, value);
     
}
Last edited on
The cout stream buffers its output. To make sure it has written the output before you prompt for input, add cout.flush() before the call to getline().

Use a constant to set the size of the Map_code and use a for loop to read and write it. Also increment i in the "for" clause to make it clear how the loop works:
1
2
3
4
5
6
7
8
9
10
11
12
    const unsigned MapSize = 10;
    string Map_code [MapSize];
    ifstream Map_data("Map_data.data");
    cout <<"Reading file...";
    for (int i=0; i < MapSize; ++i) {
	Map_data >> Map_code[i];
    }
    for (int i=0; i < MapSize; ++i) {
	cout << Map_code[i];
    }
    for (int i = 0; i < MapSize; ++i) {
        ....
Topic archived. No new replies allowed.