Thread: easiest way of writing all the contents of

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    222

    easiest way of writing all the contents of

    I have a class definition as the following

    Code:
    class SimulationTiming
    {
    public:
    	LARGE_INTEGER freq;
    	LARGE_INTEGER startTime;
    	LARGE_INTEGER stopTime;
    
    	vector<float>	locateNeedleTime;
    	vector<float>	setConstraintAngleTime;
    	vector<float>	checkSurfaceTime;
    	vector<float>	addNodeTime;
    	vector<float>	computeThresholdsTime;
    	vector<float>	resolveInterceptTime;
    	vector<float>	mmult2time;
    	vector<float>	updateLCSXYZtime;
    	vector<float>	BCCtime;
    	vector<float>	ConstraintDispXYZtime;
    	vector<float>	ConstriantDispXZtime;
    	vector<float>	UpdateLCSXZtime;
    	vector<float>	solvesystemtime;
    	vector<float>	projectiontime;
    	vector<float>	computeNNDistanceTime;
    	vector<float>	projectforcestime;
    	vector<float>	integrateforcestime;
    	vector<float>	findallnodestime;
    	vector<float>	solveneedlespringtime;
    	vector<float>	initvartime;
    
    public:
    	SimulationTiming(void);
    	void startTimer(void);
    	void stopTimer(vector<float> *list);
    	~SimulationTiming(void);
    };
    I'm trying to write all the vector contents into its own text file. However, I'm not sure what's the easiest way of doing so. I have looked into fwrite, fprintf, and fstream classes, but not sure about the easiest way to go in terms of dumping the contents for a vector into a file. An example would be much appreciated. Thanks.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Code:
    	vector<float>	locateNeedleTime;
    	vector<float>	setConstraintAngleTime;
    	vector<float>	checkSurfaceTime;
    	vector<float>	addNodeTime;
    	vector<float>	computeThresholdsTime;
    	vector<float>	resolveInterceptTime;
    	vector<float>	mmult2time;
    	vector<float>	updateLCSXYZtime;
    	vector<float>	BCCtime;
    	vector<float>	ConstraintDispXYZtime;
    	vector<float>	ConstriantDispXZtime;
    	vector<float>	UpdateLCSXZtime;
    	vector<float>	solvesystemtime;
    	vector<float>	projectiontime;
    	vector<float>	computeNNDistanceTime;
    	vector<float>	projectforcestime;
    	vector<float>	integrateforcestime;
    	vector<float>	findallnodestime;
    	vector<float>	solveneedlespringtime;
    	vector<float>	initvartime;
    Are these all updated at the same time?
    If so, I would suggest you make a struct
    Code:
    struct data   // Use a better name!
    {
    	float	locateNeedleTime;
    	float	setConstraintAngleTime;
    ...
    	float	initvartime;
    };
           vector<data> dataVector;
    Once you have that, you could define a operator<< for a data element, that outputs all the elemets of one struct to a output stream. That is the common way to do this sort of thing.

    It's not trivial, but not too bad either.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    222
    The vector members are not updated at the same time. I found something on Google with more appropriate search terms to come up with something like C++ : Outputting a vector to a file, and other problems. - Topic Powered by Eve For Enterprise for writing the contents of a vector to a file. Thanks for your help though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Writing encrypted value to file.
    By mkthnx001 in forum C++ Programming
    Replies: 13
    Last Post: 05-25-2009, 12:42 PM
  2. buffer contents swapping
    By daluu in forum C++ Programming
    Replies: 7
    Last Post: 10-14-2004, 02:34 PM
  3. combining file contents with command line
    By pxleyes in forum C Programming
    Replies: 4
    Last Post: 04-12-2004, 10:27 PM
  4. writing functions
    By jlmac2001 in forum C++ Programming
    Replies: 5
    Last Post: 09-20-2003, 12:06 AM
  5. Writing Bitmap Files
    By HappyDude in forum C++ Programming
    Replies: 1
    Last Post: 10-13-2001, 05:48 PM