Array Troubles

Hi people, i' m new here and new with C++ and programming in general.

I have a file which structure is STRING double double double

for many many lines, so i wanna create a vector which has the columns and lines of my file, and prin them in a new file (just for start), the code I've written is

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

typedef struct ATOM {string id; double x ; double y; double z;} atom;
typedef struct BODY {atom a1; atom a2; atom a3; double z[3];} body;

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

if (argc < 5)
{
        cout << "eulertrj input_file Natoms Nframes output_file" << endl;
        exit(1);
}

int natoms = atoi(argv[2]);
int nframes = atoi(argv[3]);
fstream t(argv[1]); 
ofstream e(argv[4]);

int itmp;
string s;
string q;
double rx, ry, rz;

atom pbody[natoms];

for (int nf = 0; nf < nframes; nf++)
        {
                t >> itmp >> s >> s >> s;
                for (int na = 0; na < natoms; na++)
                {
                //      cout << na;
                        t >> pbody[na].id >> pbody[1].x >> pbody[2].y >> pbody[3].z;
                        e << gets(pbody)[na] << "       " << pbody[3] << endl;
                };
        };

return 0;
}
[\code]

when I complite it, it's  a disaster

[code]

[me@delta18 newmodel]$ c++ eulertrj.cpp -o eulertrj

eulertrj.cpp: In function ‘int main(int, char**)’:
eulertrj.cpp:38: error: no match for ‘operator<<’ in ‘e << pbody[na]’
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/ostream:108: note: candidates are: std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>& (*)(std::basic_ostream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/ostream:117: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/ostream:127: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/ostream:165: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/ostream:169: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/ostream:173: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(bool) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/ostream.tcc:91: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/ostream:180: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(short unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/ostream.tcc:105: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/ostream:191: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/ostream:200: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/ostream:204: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/ostream:209: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/ostream:213: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(float) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/ostream:221: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(long double) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/ostream:225: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(const void*) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/lib/gcc/x86_64-redhat-linux/4.4.1/../../../../include/c++/4.4.1/bits/ostream.tcc:119: note:                 std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]
 


i know the problem is in the line
e << pbody[na] << " " << pbody[3] << endl;

but i dnot understand...can you help me?

Thanks a lot
Line 38 does not make sense. What are you trying to do?

Read here http://www.cplusplus.com/reference/clibrary/cstdio/gets/ what gets() does.

To output pbody[3] it's according to the input on line 37 just with <<. You can override the operator<<() (or operator>>()) so that it works the way on line 38 though
Topic archived. No new replies allowed.