Jump to content
  • Advertisement
Sign in to follow this  

Using fstream Specific Question

This topic is 5044 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok this is what I'm trying to do; I want to have a program where it reads a .txt and according to that .txt displays statistics. In the .txt I'm going to put movie clip names and there length. The program will add it all up and do some other stuff (I'm making a counter-strike video so I figured this might be a useful lil program). So I might have the .txt like:
dust2_deagle.dem 1028:12:310 .51
aztec_awp.dem 523:2:234 .15
dust2_spray.dem 34:2342:234 1.0
The ###:###:## can be a string so I think I'm going to have one string array and one int array (I might use a two vectors instead). So how would I have fin be able to detect the next clip or time? (pretty much the next line).

Share this post

Link to post
Share on other sites
Read the whole line into a string, put the string in a stringstream, then use the stringstream to parse the line elements.

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <deque>

struct clip
std::string name;
std::string length;
float foo;

std::deque<clip> clips;

std::ifstream ifs("movies.txt");
std::istringstream iss;
std::string line;
unsigned int lineno = 1;

std::getline(ifs, line);

clip tmp;

iss >> clips.back().clipname
>> clips.back().length
>> clips.back().foo;

clips.push_back( tmp );
std::cerr << "Parse failure at line " << lineno << std::endl;

iss.clear(); // clears the flags (specifically, eof_bit)

Share this post

Link to post
Share on other sites
Hurray I did it. I made it so that you have a .txt file with this format:

filename.dem time length self-rating/5

Because when you make Counter-Strike movies, you have to make a bmp for every frame (you use 30 fps when recording a movie from CS) I have a const float for average bmp size. My program displays total length of movie, average rating/5, total uncompressed size, harddrive space - total uncompressed size. That was a LOT easier that I thought. Thanks for the help.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!