1.

Solve : String stuff c++?

Answer» 0    >object_p/long1.png<  x=0 y=226
1    >object_p/long1.png<  x=639 y=226
2    >object_p/long1.png<  x=1279 y=226
3    >object_p/p4.png<  x=215 y=142
4    >object_p/p5.png<  x=457 y=90
5    >object_p/p6.png<  x=691 y=61
6    >object_o/box1.png<  x=775 y=37
7    >object_o/car5.png<  x=618 y=180
8    >object_o/signright.png<  x=5 y=195
9    >object_o/signup.png<  x=206 y=197
10    >object_o/lamp2.png<  x=113 y=113
11    >object_o/lamp2.png<  x=545 y=120
12    >object_o/lamp3.png<  x=936 y=161
13    >object_o/car5.png<  x=1019 y=181
14    >object_o/car6.png<  x=832 y=192
15    >object_p/block3.png<  x=768 y=175
16    >object_p/block2.png<  x=1225 y=177
17    >object_p/p4.png<  x=1355 y=71

i have those information above store as a txt file.
in c++
How i can retrive only the file path and store it in array string?
file path are located between > path <
Thank youSo FAR i got to this

ifstream levelFile ("levels/lv1/level.txt");
   int start, end;
   if (levelFile.is_open())
   {
      string line;
      getline(levelFile,line);   //this is used to skip the first line
      while ( levelFile.good() )
      {
         getline(levelFile,line);
         for (int i = 0; i < line.length(); i++)
         {
            char newLine[100];
            strcpy_s(newLine, line.c_str());
            
            if (line.at(i) == ">" ) { start = i; }    << why cant i do this
            if (newLine == "<") { end = i; }   << why cant i do this
         }   
      }
      levelFile.close();
   } else cout << "Unable to open file";
it doesnt matter now ive DONE it.... SORRY for posting but i was really frustrated but with abit of reading i wont be posting problem againb until i really need help.

Solutions

ifstream levelFile ("game_resource/lv1.txt");
   int start, end;
   string fPath;
   char NL[] = ">";
   char nt[] = "<";
   if (levelFile.is_open())
   {
      string line;
      getline(levelFile,line);   //this is used to skip the first line
      while ( levelFile.good() )
      {
         getline(levelFile,line);
         for (int i = 0; i < line.length(); i++)
         {
            if (line == nl[0]) { start = i; }  <<btw line is suppose to be line(i)
            if (line == nt[0]) { end = i; }
         }
end = end - start;
         fPath = line.substr(start, end);
      }
      levelFile.close();
   } else cout << "Unable to open file";


Discussion

No Comment Found