Writing to Multiple files

Write your question here.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
  #include "stdafx.h"
#include<sstream>
#include<fstream>
#include<iostream>
#include <cstdlib>
#include <algorithm>
#include<list>
#include<math.h>
#include<conio.h>
#include<string>
#include "matrix.h"
#define PI 3.14159265
using namespace std;

ifstream fileinput;
ofstream fileoutput;

int main(){
int count=0;
   long line_No=0;
   double temp5;
   fileinput.open("12.txt");
   fileoutput.open("output.txt");
   if(!fileinput) { // file couldn't be opened.
      cerr << "Error: file could not be opened" << endl;
      exit(1);
   }
   while(!fileinput.eof()){
	  std::string line,id,timestep,word,wordOne,temp6,temp7,temp8;
	  double temp5;
			matrix temp;
			getline(fileinput,line);
			stringstream linestring(line);
			linestring >> id  >> temp.tag >> word >>temp6>>temp7>>temp8;
			
/*//if(fileinput)
{
    fileinput.seekg (temp5, fileinput.end);
    int length = fileinput.tellg();
    fileinput.seekg (temp5, fileinput.beg);
}*/
			if (word == "Position")
			{
				double d;
				//cout<<id<<" "<<temp.tag<<" "<<temp6<<endl;
				stringstream s1(temp6);
				s1 >> d;
				
				fileoutput<<temp.tag<<" "<<temp6<<endl;
				//temp.triangle[0] =d;
				/*
				temp.computeAngle();
				istringstream istring (id);
                int temp_id;
                istring >> temp_id;
			//	fileout(temp_id, temp.tag, temp.angle);
				*/
				
			}
       }

}


Hello all,above is my code.output should be written according to the number in temp.tag.Can any one help me with this.Thanks
It's a bad habit to create variables at the beginning of loops like you do on Line 29. I honestly can't read this because of how you have your variables named. You would be doing yourself a great service if you just did a simple find and replace (Ctrl + R in Code::Blocks) to update the names to something that makes sense for their context.
Probably a good idea to clean up your code and put in comments before posting it here, especially if you use temp5 - temp8 which means nothing to anyone but you. I also recommend to describe what the program is doing or supposed to do.

You define double temp5; twice.

I don't understand what temp.tag is, you didn't show any examples of input and it doesn't appear to be defined.
Topic archived. No new replies allowed.