ifstream not working in program

I dont knwo whats going on here, this ifstream is not working at all, its this one: Line 40: ifstream getMap(directory.append(mapName));

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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <iostream>
#include <string>
#include <fstream>
#include <cctype>
#include <vector>
#include <sstream>
#include <SFML/Graphics.hpp>

using namespace std;

int main()
{
    string directory = "Resources/Maps/"; //Set directory for the maps
    ifstream mapList("MapList.txt");

    string line;
    string tileName;
    string mapName;

    vector<vector<sf::Vector2i> > map;
    vector<sf::Vector2i> tempMap;

    sf::Texture tileTexture;
    sf::Sprite tiles;

    if(mapList.is_open())
    {
        while(!mapList.eof())
        {
            while(getline(mapList, line))
            {
                    tileName = line.substr(line.find(":") + 1);
                    cout << tileName << endl;
                    mapName = line.substr(0, line.find(":"));
                    cout << mapName << endl;
            }
        }
    }
    
    ifstream getMap(directory.append(mapName));

    if(getMap.is_open())
    {
        tileTexture.loadFromFile(tileName);
        tiles.setTexture(tileTexture);

        while(!getMap.eof())
        {
            string str, value;
            getline(getMap, str);
            stringstream stream(str);

            while(getline(stream, value, ' '))
            {
                if(value.length() > 0)
                {
                    string xx = value.substr(0, value.find(','));
                    string yy = value.substr(value.find(',') + 1);

                    int x, y, i, j;
                    for(i = 0; i < xx.length(); i++)
                    {
                        if(!isdigit(xx[i])){break;}
                    }
                    for(j = 0; j < yy.length(); j++)
                    {
                        if(!isdigit(yy[j])){break;}
                    }

                    x = (i == xx.length() ? atoi(xx.c_str()) : -1);
                    y = (j == yy.length() ? atoi(yy.c_str()) : -1);

                    tempMap.push_back(sf::Vector2i(x, y));
                }
            }

            map.push_back(tempMap);
            tempMap.clear();
        }
    }

    sf::RenderWindow window(sf::VideoMode(800, 600, 32), "Loading Tile Maps");

    while(window.isOpen())
    {
        sf::Event event;
        while(window.pollEvent(event))
        {
            switch(event.type)
            {
                case sf::Event::Closed:
                {
                    window.close();
                }break;
                case sf::Event::Resized:
                {
                    sf::FloatRect visibleArea(0, 0, event.size.width, event.size.height);
                    window.setView(sf::View(visibleArea));
                }break;
            }
        }
        window.clear(sf::Color(0, 240, 255));

        for(int i = 0; i < map.size(); i++)
        {
            for(int j = 0; j < map[i].size(); j++)
            {
                if(map[i][j].x != -1 && map[i][j].y != -1)
                {
                    tiles.setPosition(j * 32, i * 32);
                    tiles.setTextureRect(sf::IntRect(map[i][j].x * 32, map[i][j].y * 32, 32, 32));
                    window.draw(tiles);
                }
            }
        }

        window.display();
    }
}


Error

C:\Users\thund_000\Desktop\view test\main.cpp|40|error: no matching function for call to 'std::basic_ifstream<char>::basic_ifstream(std::basic_string<char>&)'|


This worked before so I don't knwo whats going on.
Last edited on
If you are not using C++11 or later you can't pass a std::string to the ifstream constructor, but instead you have to pass a C string (const char*).
 
ifstream getMap(directory.append(mapName).c_str());

Ah I forgot about that, I had it set in my other project but I started a new one. Thank you.
Topic archived. No new replies allowed.