Problem with ifstream

closed account (10oTURfi)
EDIT: Never mind, solved it.

This program is supposed to read a file of this format:
string int int char

for example;
add 26 12 M

And then move cursor to the right coordinates and print out the character
But I get this error at line 34:
1>c:\documents and settings\drago\desktop\mislav\console learning project\console-learning-project\replay\src\main.cpp(34) : error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)

But if I comment it out I get
1>c:\documents and settings\drago\desktop\mislav\console learning project\console-learning-project\replay\src\main.cpp(47) : error C2065: 'Replay' : undeclared identifier
1>c:\documents and settings\drago\desktop\mislav\console learning project\console-learning-project\replay\src\main.cpp(47) : error C2228: left of '.close' must have class/struct/union
1> type is ''unknown-type''

Which doesnt make much sense to me beacuse at line 13
ifstream Replay(argv[1]);
This is the whole thing:
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
49
#include "console.h"

int main(int argc, char *argv[])
{
    //Get the right file
    if (argc != 2)
    {
        cout<<"Usage: "<< argv[0] <<" <filename>.txt" << endl;
        return 1;
    }
    else 
    {
        ifstream Replay(argv[1]);

        if (!Replay.is_open())
        {
            cout<<"Could not open file" << endl;
            return 2;
        }

        //Init
        string command;
        int coordX;
        int coordY;
        char output;
        AltEnter();
        for(int a=0; a<36; a++)
        {
            for(int b=0; b<36; b++)
                cout << " |";
            cout << endl;
        }

        while(Replay >> command >> coordX >> coordY >> output)
        {
            GotoXY(coordX, coordY);

            if(command == "add")
                cout << output;

            else if(command == "del")
                cout << " ";
        }
    }

    GotoXY(0, 37);
    Replay.close();
    return 0;
}


Please help :)
Last edited on
Topic archived. No new replies allowed.