|
-
November 29th, 2009, 03:08 AM
#1
Read File problem
Hello, i am trying to read many different files. The filename has to change to different numbers. It loops 25 times.
For example the first run i want it to ifstream myfile3 (npcs/npc1.txt); but the second run i want it to ifstream myfile3 (npcs/npc5.txt);
so lets say...
npcmapdata[1] = 1
npcmapdata[2] = 5
npcmapdata[3] = 35
I tried this, but i get the error message '+' : cannot add two pointers. I have tried converting it to a string but then i get tons of errors. I really need some help on how to accomplish this. thank you very much.
Code:
while (npcloop < 25)
{
npcloop++;
string account2 = "npcs/" + "npc" + npcmapdata2[npcloop] + ".txt";
ifstream myfile3 (account2.c_str());
if (myfile3.is_open())
{
while (! myfile3.eof() )
{
getline (myfile3,npc);
etc etc
}
I know its very confusing, but basically i want my file reading loop to constantly change filenames to a number that i am holding in npcmapdata2 arrays.
Thank you very much for any help i receive
-
November 29th, 2009, 03:15 AM
#2
Re: Read File problem
char buffer[300];
sprintf(buffer, "npcs/npc%d.txt", npcmapdata2[npcloop]);
string account2 = buffer;
or:
sprintf(buffer, "%s%s%d%s", "npcs/", "npc", npcmapdata2[npcloop], ".txt");
-
November 29th, 2009, 03:19 AM
#3
Re: Read File problem
Thank you so very much. Also the fast response was great .
-
November 29th, 2009, 08:57 AM
#4
Re: Read File problem
I think it would look a lot nicer (and be safer) if it was done in c++.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|