Sign in to follow this  
mxma1

Using fstream Specific Question

Recommended Posts

mxma1    140
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
Fruny    1658
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;

while(!ifs.eof())
{
std::getline(ifs, line);
iss.str(line);

clip tmp;

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

if(!iss.fail())
clips.push_back( tmp );
else
std::cerr << "Parse failure at line " << lineno << std::endl;

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

Share this post


Link to post
Share on other sites
mxma1    140
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this