I'm not sure if I should ask here. The program worked it's just that I'm not satisfied how I implemented it because I used two while loop to read a specific data and I have no idea what am I doing. How can I make it more efficient and instead of using two while loop
?
spritesheet.txt
int main() {
fstream file("spritesheet.txt");
int x, y, width, height;
string num1, num2;
string line;
string data;
if (file.is_open())
{
while (getline(file, line))
{
if (line == "enemy")
{
while (file >> data >> num1 >> num2)
{
if (data == "xy:")
{
x = std::stoi(num1);
y = std::stoi(num2);
cout << "x: " << x << endl << "y: " << y << endl;
}
if (data == "size:")
{
width = std::stoi(num1);
height = std::stoi(num2);
cout << "width: " << width << endl << "height: " << height << endl;
}
}
file.close();
break;
}
}
}
system("pause");
}
using namespace std;
\$\endgroup\$