![]() |
|
|
|
| ||||||
|
Welcome to the The ProgrammersTalk Community forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
![]() |
![]() | | LinkBack | Thread Tools | Display Modes | ![]() |
| |
| |||
| There's nothing obviously wrong with the code you've posted, perhaps you could post a more complete example program which displays the problem. As an aside, you have a couple of redundant lines of code there; namely Code: ss.seekg(std::ios::beg); also Code: if(Line.empty()) { continue; } However, neither of these will affect the output you're seeing; I suspect the problem is either related to your File, or to the way you're directing output from your program |
| The Following User Says Thank You to Bench For This Useful Post: | ||
MrPickle (10-12-2008) | ||
| ||||
| Without the seekg it doesn't output the later lines, here's an example I made to show that: Example.zip I don't know what I'm doing to get it to output the first character twice, here's my exact code: Code:
template<typename T>
T FromStringTo(std::string String) { return boost::lexical_cast<T>(String); }
void StringReplace(std::string *String, std::string Strip, std::string Replace) {
int Position = String->find(Strip);
while(Position != String->npos) {
String->replace(Position, 1, Replace);
Position = String->find(Strip, Position + 1);
}
}
Obj::Obj(std::string Filename) {
Loaded = false;
std::ofstream Out("Obj.txt");
std::ifstream File(Filename.c_str(), std::ios::in);
if(!File.is_open()) { std::runtime_error("Unable to open \"" + Filename + "\""); exit(1); }
std::string Line, Word, Type;
std::stringstream LStream;
std::vector<std::string> LVector;
Vertex V;
Polygon P;
while(std::getline(File, Line)) {
if(Line.empty()) { continue; }
StringReplace(&Line, "/", " ");
LStream.str(Line);
LStream.seekg(std::ios::beg);
Out << "----------------------------------------------\n" << Line << "\n"; Out.flush();
while(LStream >> Word) { LVector.push_back(Word); }
for(int i = 0; i < LVector.size(); i++) Out << LVector[i] << "\n"; Out.flush();
Type = LVector.at(0);
Out << Type << "\n";
if(Type == "v") {
V.x = FromStringTo<float>(LVector.at(1));
V.y = FromStringTo<float>(LVector.at(2));
V.z = FromStringTo<float>(LVector.at(3));
Vertices.push_back(V);
} else if(Type == "f") {
switch(LVector.size()) {
case 4:
for(int i = 0; i < 3; i++) {
P.Vertices[i] = FromStringTo<int>(LVector.at(i + 1));
}
case 7:
for(int i = 0; i < 3; i++) {
P.Vertices[i] = FromStringTo<int>(LVector.at(2 * i + 1));
}
case 10:
for(int i = 0; i < 3; i++) {
P.Vertices[i] = FromStringTo<int>(LVector.at(3 * i + 1));
}
}
Faces.push_back(P);
Out << LVector.size() << "\n";
}
LVector.clear();
}
Path = Filename;
Loaded = true;
Out.flush();
} |
![]() |
| Thread Tools | |
| Display Modes | |
| |