You are not logged in.

  • Login

Dear visitor, welcome to Coder Forum. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Wednesday, February 13th 2008, 2:02pm

Probleme mit ifstream (Filename kommt aus einer map)

Moin,

ich habe hier ein kleines Problem, beim öffnen von Files.

Ich habe die Filenames in einer Map gespeichert, wo auch deren größe noch mit aufgenommen werden soll:

map <string, map <string, int> >

lese ich die Filenames aus der Map aus (erster String) und laß ihn mittels cout ausgeben, erhalte ich auch den Filename.

Übergebe ich den Filename aber ifstream:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
typedef map <string, int> t_map;
typedef map <string, t_map> t_files;
typedef t_files::iterator i_files;

t_files FILES;

i_files start = FILES.begin();
i_files end = FILES.end();

while (start != ende)
{
	string filename = start->first;

	ifstream file(filename.c_str());

	if (file)
	    mach was...
	start++;
}


Wird das File nicht geöffnet (file.good() liefert auch 0 zurück). Gebe ich aber exact den gleichen Filename mittels ifstream file("datei") an, funktioniert alles wie es soll.

Ich habe derzeit keine Ahnung, woran es liegen könnte, aber ich denke mal es liegt daran, das ie Filenames aus der Map kommen (die liegen da mit einem Backslash als String, also "c:\hsdjkfh\dfhs" drin). Oder muss ich die Backslashes auch in der Map noch escapen?

Thomas

2

Wednesday, February 13th 2008, 4:10pm

Leider kann ich den Beitrag nicht mehr löschen, hab das problem jetzt noch gefunden.

Der string hatte am Ende noch ein 0x0d, deswegen kam ifstream durcheinander, denke ich mal.

Thomas

Similar threads

Social bookmarks