I have a problem with my program. When I try to open it, it closes again, just like if I did not have system("PAUSE"); at the end. This did not happen until I tried to use my loadFromFile() function.
Any ideas on what is causing the trouble? I also tried to add a cin >>, but same thing happen.
Just so you know, the loadFileFunction is work in progress so please dont kill me for bad stuff in it.
Here is my main.cpp
#include "Input.h" // This is the only header I get info from now
using namespace std;
int main(int argc, char *argv)
cout << " OK raytracer " << endl;
cout << " ---------------------------------------\n" << endl;
stuff = loadFromFile("c:\\testFile.txt");
cout << "done" << endl;
std::vector<Triangle> loadFromFile(char* FileName)
std::string currentLine; // Variable that holds the current line
// we are using.
int nrLines = 0; // Variable for checking how many lines
// there are in the file
// Open file
std::ifstream myFile (FileName);
// While the file is open, we read the info and construct triangles
while (! myFile.eof())
// Read line
// Check if this line holds vertex information. If the line starts
// with V, we will use it.
if (currentLine == 'V')
// Break the line into different components, so that we can
// create 3 different vertexes for each cordinate in the file
// V: 0.0,0.0,0.0 - 1.0,1.0,1.0 - 2.0,2.0,2.0
// An array of strings, for reading the 3 vertexes we will later
// Variable for keeping track of which character in currentLine
// we are reading, it starts at 2, as the 3 first characters
// are not part of the number we are tring to read
int x = 2;
// Make a loop for creating 3 vertexes
for (int i = 0; i < 3; i++)
// Make sure the vertex string we are writing to now is
// Make sure the current character is part of the number
while (currentLine[x] != '.' || currentLine[x] != ' ')
// If the current character is part of a number,
// append it to the vertex string
std::cout << vertex[i] << " "; // Temp line for printing
std::cout << std::endl; // Temp line for printing
// Convert the vertex arrays into numbers, so we can use them
// to create triangles.
// Increment the line counter
// Finished with reading the file, close it
// Read the cordinates of the three first vertexes
// and pass them to a new triangle
// Continiu this until file is finished
// Return the vector array of triangles