473,508 Members | 2,091 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

struct ?

I am working on the data struc. below:
is there way I can abbrev. the expression below to avoid long
expression.
Thanks......
///////////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
const int MAX=50;
struct Record_info {
string bypassed;
string name;
int midterm;
double quiz;
double final;
string testname;
}student[MAX],*ptrstudent;

int main (void){
ptrstudent = student;
ifstream in ("test2.txt");
string line;
string line2;
char buffer[40];
while (getline(in,line)){
if (line.find("#")!=string::npos)continue ;
istringstream anyname(line);

/////////// HOW CAN I ABBREV. EXPRESSION BELOW ?
////////////////////////////////////////

anyname>>ptrstudent->bypassed>>ptrstudent->name>>ptrstudent->midterm;

anyname>>ptrstudent->quiz>>ptrstudent->final>>ptrstudent->testname;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ptrstudent++;
}
}

Nov 24 '05 #1
5 1708
tvn007 wrote:
struct Record_info {
string bypassed;
string name;
int midterm;
double quiz;
double final;
string testname;
istream& operator>> (istream& is) (
is >> bypassed;
is >> name
is >> midterm;
is >> quiz
is >> final;
is >> testname;
return is;
}
}student[MAX],*ptrstudent;

int main (void){
ptrstudent = student;
ifstream in ("test2.txt");
string line;
string line2;
char buffer[40];
while (getline(in,line)){
if (line.find("#")!=string::npos)continue ;
istringstream anyname(line);

/////////// HOW CAN I ABBREV. EXPRESSION BELOW ?
////////////////////////////////////////

anyname>>ptrstudent->bypassed>>ptrstudent->name>>ptrstudent->midterm;

anyname>>ptrstudent->quiz>>ptrstudent->final>>ptrstudent->testname;
anyname >> *ptrstudent;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ptrstudent++;
}
}

Nov 24 '05 #2
In message <43***********************@news.newshosting.com> , Ron Natalie
<ro*@spamcop.net> writes
tvn007 wrote:
struct Record_info {
string bypassed;
string name;
int midterm;
double quiz;
double final;
string testname;
istream& operator>> (istream& is) (


If its _left_ operand is to be an istream, this can't be a member
function of Record_info. It has to be a non-member function with two
arguments.

friend istream & operator>>(istream & is, Record_info & rec) {
is >> bypassed; is >> rec.bypassed; // etc. is >> name
is >> midterm;
is >> quiz
is >> final;
is >> testname;
return is;
}
}student[MAX],*ptrstudent;


int main (void){
ptrstudent = student;
ifstream in ("test2.txt");
string line;
string line2;
char buffer[40];
while (getline(in,line)){
if (line.find("#")!=string::npos)continue ;
istringstream anyname(line);
/////////// HOW CAN I ABBREV. EXPRESSION BELOW ?
////////////////////////////////////////


anyname>>ptrstudent->bypassed>>ptrstudent->name>>ptrstudent->midterm;

anyname>>ptrstudent->quiz>>ptrstudent->final>>ptrstudent->testname;


anyname >> *ptrstudent;

///////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////
ptrstudent++;
}
}


--
Richard Herring
Nov 24 '05 #3
I am not sure if it will work since I am using struct array and
pointer.

struct Record_info {
string bypassed;
string name;
int midterm;
double quiz;
double final;
string testname;
}student[MAX],*ptrstudent;
ptrstudent = student;

anyname>>ptrstudent->bypassed>>ptrstudent->name>>ptrstudent->midterm;
anyname>>ptrstudent->quiz>>ptrstudent->final>>ptrstudent->testname;

Nov 24 '05 #4
tvn007 <tv****@hotmail.com> wrote:
I am not sure if it will work [..]


Have you tried it?
--
jb

(reply address in rot13, unscramble first)
Nov 24 '05 #5
In message <11**********************@g43g2000cwa.googlegroups .com>,
tvn007 <tv****@hotmail.com> writes
I am not sure if it will work
Not sure if _what_ will work? Please quote some context.
since I am using struct array and
pointer.
I don't think that's relevant. Fundamentally you want to implement
operator>>(istream&, Record_info &). If the Record_info happens to be an
array element or the target of a pointer it makes no difference.
struct Record_info {
string bypassed;
string name;
int midterm;
double quiz;
double final;
string testname;
}student[MAX],*ptrstudent;
ptrstudent = student;

anyname>>ptrstudent->bypassed>>ptrstudent->name>>ptrstudent->midterm;
anyname>>ptrstudent->quiz>>ptrstudent->final>>ptrstudent->testname;


anyname >> *ptrstudent;

--
Richard Herring
Nov 24 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
17568
by: Roy Hills | last post by:
When I'm reading from or writing to a network socket, I want to use a struct to represent the structured data, but must use an unsigned char buffer for the call to sendto() or recvfrom(). I have...
10
3486
by: Rick Anderson | last post by:
All, I am receiving the following compilation error on LINUX (but not Solaris, HPUX, WIN32, etc): compiling osr.c LBFO.h(369): warning #64: declaration does not declare anything extern...
5
3278
by: PCHOME | last post by:
Hello! I am working on dividing a single C file into several files. Now I encounter a problem about the global variables and can not find a way to solve it. All global variables and codes used...
19
2590
by: Russell Shaw | last post by:
Hi, I have two structs in a header file, and they reference each other, causing a compile error. Is there a standard way to deal with this? typedef struct { ... RtAction *actions; }...
16
3810
by: burn | last post by:
Hello, i am writing a program under linux in c and compile my code with make and gcc. Now i have 4 files: init.c/h and packets.c/h. Each header-file contains some: init.h: struct xyz {
5
4311
by: Johs32 | last post by:
I have a struct "my_struct" and a function that as argument takes a pointer to this struct: struct my_struct{ struct my_struct *new; }; void my_func(struct my_struct *new); I have read...
7
2247
by: Alex | last post by:
If I have two struct. See below: struct s1 { int type; int (*destroy)(struct s1* p); } struct s2 { struct s1 base;
4
5052
by: hobbes992 | last post by:
Howdy folks, I've been working on a c project, compiling using gcc, and I've reached a problem. The assignment requires creation of a two-level directory file system. No files have to be added or...
4
9783
by: hugo.arregui | last post by:
Hi! I have two struts like that: struct { int num; int num2; struct b arrayOfB; } a;
4
2757
by: Sheldon | last post by:
Hi, I have a unique case where I need an array of structs that grows and within this array is another struct that grows in some cases. I'm having trouble allocating memory. Since I have never...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7326
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7385
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5053
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1558
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.