Sponsored Content
Top Forums Programming Dynamically enumerating the members of a C++ struct Post 302810931 by figaro on Wednesday 22nd of May 2013 05:56:32 PM
Old 05-22-2013
Dynamically enumerating the members of a C++ struct

In C++ there is a struct with the following structure:

Code:
typedef struct myStruct
{
    string s_date;
    float fA;
    float fB;
    float fC;
    .....
    float fZ;
} myData;

After some computations on the values of the struct members are inserted into a database table:

Code:
myData ind;
string sqlInsert = "INSERT INTO calculations (date, A, B, C, ..., Z) 
VALUES ('"+ind.s_date+"','"+ftostr(ind.fA)+"','"+ftostr(ind.fB)+"','"+ftostr(ind.fC)+"','"+ ... +"','"+ftostr(ind.fZ)+"')";

Given that the members of the struct can change, as well as currently close to 100 members, we are looking for a way to loop over the members in a dynamic fashion, without having to spell out each member individually.

Therefore the question is, is there a way to loop over the struct members so that the SQL that comes after the VALUES clause is updated based on however many struct members there are?
 

9 More Discussions You Might Find Interesting

1. Programming

save a struct

hi all , can i save a structure in c in a file? how ? help me , thx. :) (2 Replies)
Discussion started by: kall_ANSI
2 Replies

2. Programming

struct tm problem

I receive an integer as argument for a function. within function definition i want it to be of type struct tm. eg.. main() { int a; ...... } function(...,..,a,..) int a; { struct tm tm; if(!a) ^ time(&a); ^ ... (4 Replies)
Discussion started by: bankpro
4 Replies

3. Programming

Enumerating hardware

I am trying to enumerate all hardware (plugged in devices) and I am using lshal source code from here: Cross Reference: /onnv/onnv-gate/usr/src/cmd/hal/tools/lshal.c and is missing information about plugged in monitors, and mouse and houppgae TV card. They came out in gnome device manager,... (0 Replies)
Discussion started by: gyula
0 Replies

4. Linux

GCOV : struct bb

Hi, I am working on gcov.Meaning, analysing the functionality of gcov. There is one structure called "struct bb". I am not sure, how struct bb members are getting assigned values. If anyone knows how it is happening pls let me know. Thanks in advance. --Vichu (0 Replies)
Discussion started by: Vichu
0 Replies

5. UNIX for Dummies Questions & Answers

How to access a struct within a struct?

Can someone tell me how to do this? Just a thought that entered my mind when learning about structs. First thought was: struct one { struct two; } struct two { three; } one->two->three would this be how you would access "three"? (1 Reply)
Discussion started by: unbelievable21
1 Replies

6. UNIX for Dummies Questions & Answers

struct winsize

what is struct winsize used for? i tried looking it up, but no luck. (0 Replies)
Discussion started by: l flipboi l
0 Replies

7. Programming

Using pointers to struct members as args to functions

In a well-known book on the C language, there is an example of an efficient method for using a struct member as an argument to a function. (I'm a C noob, but I believe the correct terminology might be: use call-by-reference instead of call-by-value.) The function is printf. Anyway, here's a... (5 Replies)
Discussion started by: uiop44
5 Replies

8. Programming

Storing C++-struct in file - problem when adding new item in struct

Hi, I have received an application that stores some properties in a file. The existing struct looks like this: struct TData { UINT uSizeIncludingStrings; // copy of Telnet data struct UINT uSize; // basic properties: TCHAR szHost; //defined in Sshconfig UINT iPortNr; TCHAR... (2 Replies)
Discussion started by: Powerponken
2 Replies

9. Programming

Get struct definition

I have many headers with huge amount of structures in them, typical one looks like this: $ cat a.h struct Rec1 { int f1; int f2; }; struct Rec2 { char r1; char r2; }; struct Rec3 { int f1; float k1; float ... (6 Replies)
Discussion started by: migurus
6 Replies
ftime(3C)						   Standard C Library Functions 						 ftime(3C)

NAME
ftime - get date and time SYNOPSIS
#include <sys/timeb.h> int ftime(struct timeb *tp); DESCRIPTION
The ftime() function sets the time and millitm members of the timeb structure pointed to by tp. The structure is defined in <sys/timeb.h> and contains the following members: time_t time; unsigned short millitm; short timezone; short dstflag; The time and millitm members contain the seconds and milliseconds portions, respectively, of the current time in seconds since 00:00:00 UTC (Coordinated Universal Time), January 1, 1970. The timezone member contains the local time zone. The dstflag member contains a flag that, if non-zero, indicates that Daylight Saving time applies locally during the appropriate part of the year. The contents of the timezone and dstflag members of tp after a call to ftime() are unspecified. RETURN VALUES
Upon successful completion, the ftime() function returns 0. Otherwise -1 is returned. ERRORS
No errors are defined. USAGE
For portability to implementations conforming to earlier versions of this document, time(2) is preferred over this function. The millisecond value usually has a granularity greater than one due to the resolution of the system clock. Depending on any granularity (particularly a granularity of one) renders code non-portable. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Standard | +-----------------------------+-----------------------------+ SEE ALSO
date(1), time(2), ctime(3C), gettimeofday(3C), timezone(4), attributes(5), standards(5) SunOS 5.10 24 Jul 2002 ftime(3C)
All times are GMT -4. The time now is 11:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy