Streaming problems!

Hi people, i have this code..

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
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>
#include<cmath>
using namespace std;

void comparison(ifstream t, ifstream r);

void comparison(ifstream t, ifstream r)
	{
	while(!r.eof())
		{
	string c;
	string d;
		r >> rtmp >> c >> c >> c ;
		t >> ttmp >> d >> d >> d ;
		if(rtmp != ttmp)
		{
		cout << " Number of Atoms mismatch." << endl << endl << "Chek Reference Structure and Trajectory File ! " << endl << endl;
		exit(1);
		};
	cout << c << endl ;


	};
}
int main(int argc, char* argv[]){

/* Here is the input part, input files must be in XYZ format */

if (argc < 6)
{
	cout <<  "Missing Informations !" << endl << endl << "Input must be : ./eulertrj input_file ref_structure  Natoms Nframes output_file" << endl <<
		endl;
	exit(1);
}

ifstream t(argv[1]); 		// Trajectory File
ifstream r(argv[2]);		// Reference Structure File
ofstream o(argv[5]);		// Output File

int natoms = atoi(argv[3]);
int nframes = atoi(argv[4]);
int rtmp;
int ttmp;
int residues = (natoms-2)/8;
int nbody = residues;

// Make a comparison between reference structure and input file, number of atoms and atom sequence MUST be the same 

comparison(t,r);

return 0 ;	
}



when I compile this with c++, the output errors are

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23


retry.cpp: In function ‘void comparison(std::ifstream, std::ifstream)’:
retry.cpp:30: error: ‘rtmp’ was not declared in this scope
retry.cpp:31: error: ‘ttmp’ was not declared in this scope
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/ios:39,
                 from /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/ostream:40,
                 from /usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/iostream:40,
                 from retry.cpp:3:
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/ios_base.h: In copy constructor ‘std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)’:
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/ios_base.h:790: error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/iosfwd:47: error: within this context
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/iosfwd: In copy constructor ‘std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(const std::basic_ifstream<char, std::char_traits<char> >&)’:
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/iosfwd:81: note: synthesized method ‘std::basic_ios<char, std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)’ first required here 
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/streambuf: In copy constructor ‘std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf(const std::basic_filebuf<char, std::char_traits<char> >&)’:
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/streambuf:770: error: ‘std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char, _Traits = std::char_traits<char>]’ is private
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/iosfwd:78: error: within this context
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/iosfwd: In copy constructor ‘std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(const std::basic_ifstream<char, std::char_traits<char> >&)’:
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/iosfwd:81: note: synthesized method ‘std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf(const std::basic_filebuf<char, std::char_traits<char> >&)’ first required here 
retry.cpp: In function ‘int main(int, char**)’:
retry.cpp:66: note: synthesized method ‘std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(const std::basic_ifstream<char, std::char_traits<char> >&)’ first required here 
retry.cpp:66: error:   initializing argument 1 of ‘void comparison(std::ifstream, std::ifstream)’



I dont understand the meaning of errors....can you help me please?

Thanks!
The error says

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
void comparison(ifstream t, ifstream r)
	{
	while(!r.eof())
		{
	string c;
	string d;
		r >> rtmp >> c >> c >> c ;    //What is this rtmp?? 
		t >> ttmp >> d >> d >> d ;  // and this ttmp too
		if(rtmp != ttmp)
		{
		cout << " Number of Atoms mismatch." << endl << endl << "Chek Reference Structure and Trajectory File ! " << endl << endl;
		exit(1);
		};
	cout << c << endl ;


	};
}

Last edited on
Besides the already mentioned undeclared rtmp and ttmp, the third error message is saying that it's impossible to compile void comparison(std::ifstream, std::ifstream) because it would require copying an ifstream, which would require a call to a private copy constructor of ios_base. Pass streams by reference.
ok now rtmp and ttmp are declared

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
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>
#include<cmath>
using namespace std;

void comparison(ifstream t, ifstream r);


int main(int argc, char* argv[]){

/* Here is the input part, input files must be in XYZ format */

if (argc < 6)
{
	cout <<  "Missing Informations !" << endl << endl << "Input must be : ./eulertrj input_file ref_structure  Natoms Nframes output_file" << endl <<
		endl;
	exit(1);
}

ifstream t(argv[1]); 		// Trajectory File
ifstream r(argv[2]);		// Reference Structure File
ofstream o(argv[5]);		// Output File

int natoms = atoi(argv[3]);
int nframes = atoi(argv[4]);
int rtmp;
int ttmp;
int residues = (natoms-2)/8;
int nbody = residues;

// Make a comparison between reference structure and input file, number of atoms and atom sequence MUST be the same 

comparison(t,r);

return 0 ;	
}
void comparison(ifstream t, ifstream r)
	{
	while(!r.eof())
		{
	string c;
	string d;
		r >> rtmp >> c >> c >> c ;
		t >> ttmp >> d >> d >> d ;
		if(rtmp != ttmp)
		{
		cout << " Number of Atoms mismatch." << endl << endl << "Chek Reference Structure and Trajectory File ! " << endl << endl;
		exit(1);
		};
	cout << c << endl ;


	};
}






Cubby....ehm I don't understand what you are telling me...
Problem solved in this way!!!
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
#include<fstream>
#include<iomanip>
#include<cmath>
using namespace std;


void comparison(ifstream *t, ifstream *r);


int main(int argc, char* argv[]){

/* Here is the input part, input files must be in XYZ format */

if (argc < 6)
{
	cout <<  "Missing Informations !" << endl << endl << "Input must be : ./eulertrj input_file ref_structure  Natoms Nframes output_file" << endl <<
		endl;
	exit(1);
}

ifstream t(argv[1]); 		// Trajectory File
ifstream r(argv[2]);		// Reference Structure File
ofstream o(argv[5]);		// Output File

int natoms = atoi(argv[3]);
int nframes = atoi(argv[4]);
int rtmp;
int ttmp;
int residues = (natoms-2)/8;
int nbody = residues;

// Make a comparison between reference structure and input file, number of atoms and atom sequence MUST be the same 

comparison(&t,&r);

return 0 ;	
}
void comparison(ifstream *t, ifstream *r)
	{
int rtmp;
int ttmp;
double x,y;
int h = 0;
string c;
string d;

	do
	{
		if (h == 0)
		{
			r[0] >> rtmp >> c >> c >> c ;
			t[0] >> ttmp >> d >> d >> d ;
		}
		else
		{
			r[0] >> c >> x >> x >> x ;
			t[0] >> d >> y >> y >> y ;
		}
		if(rtmp != ttmp)
		{
		cout << " Number of Atoms mismatch." << endl << endl << "Chek Reference Structure and Trajectory File ! " << endl << endl;
		exit(1);
		};
		if (r[0].eof()) break;
	cout << c << "\t" << x <<endl ;
		h++;

	}while(true);
}







Thank you!!
Topic archived. No new replies allowed.