Question about structures
Apr 29, 2010 at 1:20am UTC
Ok so I have declared a struct type:
1 2 3 4 5
struct Protein {
string Name;
string Species;
string Sequence;
}data;
and initialized each type for the "data" variable.
1 2 3 4 5 6 7 8
getline(In, name, '\t' );
data.Name = name;
getline(In, species, '\t' );
data.Species = species;
getline(In, sequence);
data.Sequence = sequence;
I was told that I could insert the "data" variable directly into my output stream by doing "Out << data" but this doesn't produce anything but an error. I'm confused on how these types for the variable "data" are supposed to get stored into "data" without "data" being an array. This is the way I was taught to do it but why can't I output my "data" variable and have it display all 3 types? Thanks for the help.
Apr 29, 2010 at 2:13am UTC
Here's my full code... I really don't understand why this doesn't work. I get an error when I try to execute this.
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
struct Protein {
string Name;
string Species;
string Sequence;
}data;
int main () {
ifstream In;
ofstream Out;
In.open("sequences.txt" );
Out.open("genedata.txt" );
string name, species, sequence;
const int MAXNUM = 25;
Protein Genedata[MAXNUM];
getline(In, name, '\t' );
data.Name = name;
getline(In, species, '\t' );
data.Species = species;
getline(In, sequence);
data.Sequence = sequence;
Genedata[0] = data;
Out << Genedata[0];
Apr 29, 2010 at 2:15am UTC
Out << Genedata[0];
You cannot do this. You will have to output each member by itself, or overload operator <<.
Apr 29, 2010 at 2:24am UTC
So I assume I can't do "Out << data" either?
Apr 29, 2010 at 2:39am UTC
Nope.
Apr 29, 2010 at 3:16am UTC
Well I've been lied to then... I'm furious right now. Thanks for the help.
Topic archived. No new replies allowed.