Have another problem with an OBJ model format converter I'm making. As a test, I want to read in data from an OBJ file, and write it out in a different format, and then the other way around.
The problem I currently have is that I want it to be able to recognise comment files and write them without any modification. I am using istream to open the file and read the lines, but I need a way of testing whether or not the line starts with a #.
Also, I need help with reading it into a string.

Bits and pieces of my code so far:
A line with vertices (ie. "v 0.165906 -0.073740 0.414549") will have the v and the first space removed (by removing the first 2 chars), and split at the spaces, with the following code:

Vert_Out SplitVerts(string data, int id)
{
     //variable defs
     string in_data = data;
     string middle_data = "";
     string array_data[3];
     double out_data [3];
     //remove 'v' and space
     middle_data = in_data.erase(0, 2);
     //split data
     stringstream split(middle_data);
     string token;
     //i for loop
     int i = 0;
     //feed split into array
     while(split>>token){
                         array_data[i] = token;
                         i++;
     }
     //use struct for output vertex
     Vert_Out vert;
     //vert order num, [x-val, y-val, z-val] [from array]
     vert.id = id;
     vert.x = array_data[0];
     vert.y = array_data[1];
     vert.z = array_data[2];
     //return vert for use
     return vert;
}

The data is stored in the following struct:

struct Vert_Out
{
       //Vert order number, x-val, y-val, z-val
       int id;
       string x;
       string y;
       string z;
};

This is the code I have for reading the lines (I WANT THE "line" VARIABLE TO BE A STRING, NOT A CHAR ARRAY!!!)

//open infile
    ifstream infile;
    infile.open(in_path.c_str());
    //open outfile
    ifstream outfile;
    outfile.open(out_path.c_str());
    //read line
    char line[35];
    outfile.getline(line, 35);

Now I just need to get the read line into a string, and check the first letter.

Thanks for your time :)

Whoops solved it all by myself. Sorry guys.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.