Hello, I'm working on a model loader, and I'm getting a runtime error. I read the text in line by line, and read in the text using sscanf. I don't know how to explain how the error is caused, but here's my code.
The bolded text is the section of code I think is causing the problem. When ever I take that section out and recompile, it runs without an error. I'm sorry if I'm being vague on this, I just don't know how to explain it properly. Any help at all is appreciatedCode:// Include Files
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include "debug.h"
// Using standard namespace
using namespace std;
// Main Program
int main()
{
// Declare vars
vector<MESH> meshes; // Vector to hold the meshes of the model
string current_line; // Buffer for reading in the file
bool error = false;
// Open the model file and read it into the raw_data string
ifstream File("target.txt");
// Check to see if the file is open
if (!File.is_open())
{
cout << "Error loading file" << endl;
system("pause");
return 0;
}
// Read in the file line by line
while (getline(File, current_line, '\n') && error == false)
{
// Declare temp vars
short num_meshes;
short flag;
short mat_index;
string name;
// Check the current line and see it contains the mesh count
if (sscanf(current_line.data(), "Meshes: %hd", &num_meshes) == 1)
{
// Start a loop and go through each mesh
for (short i = 0; i < num_meshes && error == false; i++)
{
// Initialize a new mesh
meshes.push_back(MESH());
// Get the next line
if (!getline(File, current_line, '\n'))
{
error = true;
break;
}
// Get the mesh name
if (sscanf(current_line.data(), "\"%[^\"]\" %hd %hd", &name, &flag, &mat_index) != 3)
{
error = true;
break;
}
}
}
}
// Close the file
File.close();
system("pause");
return 0;
}
Thanks