Hi just a simple n00b question.
I need to split a string (from a .obj 3D model format) into a list of three doubles (the vertices).

example string: v 0.200006 -0.093641 0.584690

I want to make it into an array of (for example): {0.200006, -0.093641, 0.584690}

I can get rid of the 'v' and the space at the beginning, but I need to split the three vert position values using the spaces in the middle. That would probably go into an array, which I would write to a file after modification.

Thanks for your time :)

Pseudo-code:

function SplitVerts(data){
     string OutData = data
     OutData = OutData.remove(first 2 chars)
     OutData = OutData.split(" ")
     OutData = string(outdata)
     ...
     return OutData
}

Making your own importer for Direct3D hmm =). I dont remember the exact layout of a .obj fmt, but each line was something like v(for a vertex point) and then your 3 coord's which are seperated by spaces? If im reading the question right, sounds like you need to read the file line by line, and then grab your coords on each line, and do some string manipulation to get the 3 coords into different arrays for each line of the file that is read.

Sorry if im misunderstanding the question.

Edit: Just did a little rereading of question, sounds like you could make a struct consisting of 3 floats, then make an array of your struct type.

Nah I'm not making an importer. I'm just converting the data to a custom format and back as a test :)
Can you give me an example of the structs? I can comfortably use structs I just don't understand what you want me to do.
Thanks for your help :)

Provided the items are separated by whitespace, you can use the simplest form of stringstream I/O to break it apart:

#include <iostream>
#include <sstream>
#include <string>

int main()
{
    std::stringstream split("v 0.200006 -0.093641 0.584690");
    std::string token;

    while (split>> token)
        std::cout<< token <<'\n';
}

:D :D :D :D Thank you very much! My program is working! Unfortunately, I am eternally indebted to you :'(
Thanks :)

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.