Hi, I have an issue with reading from file using getline.
I know what the issue is just not how to solve it.
So I have a file with some data in it.
For example something like this:
Texture=../Textures/player.png
Name=Anders
Size=64
what I want to do is read the "key"-value up til' the '=' and do a comparison.
If I use getline(ifstream, someString, '=') the first iteration will be fine, someString will have "Texture" but the next iteration is not fine because it will read from after the '=' to the next one. So next iteration would be ../Textures/player.png\nName
I appriciate any help I can get.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
int main(){
std::ifstream stream("test.txt");
std::string s;
std::string t("Name");
while(std::getline(stream, s, '=')){
if(t == s){
//t is the same as s
//do something
}
}
return 0;
}
|