473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Storing in a Stucture

Say I have this code that is printing out:
Expand|Select|Wrap|Line Numbers
  1.     sum = convertSixteen(bp_dat);
  2.     outFile<<sum;
  3.     counter++;
  4.     if (sum ==10)
  5.         outFile<<setw(25)<<"ABMOC"<<endl<<endl;
  6.     else if (sum == 11)
  7.         outFile<<endl<<"A2C2"<<endl<<endl;
  8.     else if (sum == 12)
  9.         outFile<<endl<<"Battery CP"<<endl<<endl;
  10.     else 
  11.         outFile<<endl<<"Undefined"<<endl<<endl;
  12.  
  13.     offset+=16;
  14.     sum = convertSixteen(bp_dat);
  15.     outFile<<sum;
  16.     counter++;
  17.     if (sum ==0)
  18.         outFile<<setw(25)<<"Live Mode"<<endl<<endl;
  19.     else if (sum == 1)
  20.         outFile<<setw(25)<<"Simulation Mode"<<endl<<endl;
  21.     else 
  22.         outFile<<setw(25)<<"Undefined"<<endl<<endl;
  23.  
  24.     offset+=16;
  25.     sum = convertThirtyTwo(bp_dat);
  26.     outFile<<"TADIL-B DLRP"<<endl;
  27.     outFile<<sum<<setw(25)<<"Latitude"<<endl<<endl;
  28.     counter++;
  29.  
  30.  
  31.     offset+=32;
  32.     sum = convertThirtyTwo(bp_dat);
  33.     outFile<<sum<<setw(25)<<"Longitude"<<endl<<endl;
  34.     counter++;
  35.  
  36.  
  37.     offset+=32;
  38.     sum = convertThirtyTwo(bp_dat);
  39.     outFile<<"TADIL-B SCC"<<endl;
  40.     outFile<<sum<<setw(25)<<"Latitude"<<endl<<endl;
  41.     counter++;
  42.  
  43.     offset+=32;
  44.     sum = convertThirtyTwo(bp_dat);
  45.     outFile<<sum<<setw(25)<<"Longitude"<<endl<<endl;
  46.     counter++;
  47.  
  48.     offset+=32;
  49.     sum = convertThirtyTwo(bp_dat);
  50.     outFile<<"FAAD C2I DLRP"<<endl;
  51.     outFile<<sum<<setw(25)<<"Latitude"<<endl<<endl;
  52.     counter++;
  53.  
  54.     offset+=32;
  55.     sum = convertThirtyTwo(bp_dat);
  56.     outFile<<sum<<setw(25)<<"Longitude"<<endl<<endl;
  57.     counter++;
  58.  
  59.  
  60.     offset+=32;
  61.     sum = convertThirtyTwo(bp_dat);
  62.     outFile<<"FAAD C2I MASTER Grid Vertices"<<endl;
  63.     outFile<<sum<<setw(25)<<"North-East vertex Latitude"<<endl<<endl;
  64.     counter++;
  65.  
  66.     offset+=32;
  67.     sum = convertThirtyTwo(bp_dat);
  68.     outFile<<sum<<setw(25)<<"North-East vertex Longitude"<<endl<<endl;
  69.     counter++;
  70.  
  71.     offset+=32;
  72.     sum = convertThirtyTwo(bp_dat);
  73.     outFile<<sum<<setw(25)<<"South-East vertex Latitude"<<endl<<endl;
  74.     counter++;
  75.  
  76.     offset+=32;
  77.     sum = convertThirtyTwo(bp_dat);
  78.     outFile<<sum<<setw(25)<<"South-East vertex Longitude"<<endl<<endl;
  79.     counter++;
  80.  
  81.     offset+=32;
  82.     sum = convertThirtyTwo(bp_dat);
  83.     outFile<<sum<<setw(25)<<"South-West vertex Latitude"<<endl<<endl;
  84.     counter++;
  85.  
  86.     offset+=32;
  87.     sum = convertThirtyTwo(bp_dat);
  88.     outFile<<sum<<setw(25)<<"South-West vertex Longitude"<<endl<<endl;
  89.     counter++;
  90.  
  91.     offset+=32;
  92.     sum = convertThirtyTwo(bp_dat);
  93.     outFile<<sum<<setw(25)<<"North-West vertex Latitude"<<endl<<endl;
  94.     counter++;
  95.  
  96.     offset+=32;
  97.     sum = convertThirtyTwo(bp_dat);
  98.     outFile<<sum<<setw(25)<<"North-West vertex Longitude"<<endl<<endl;
  99.     counter++;
  100.  
  101.     outFile<<"FAAD C2I AOI"<<endl;
  102.  
  103.     offset+=32;
  104.     sum = convertThirtyTwo(bp_dat);
  105.     outFile<<sum<<setw(25)<<"Altitude"<<endl<<endl;
  106.     counter++;
  107.  
  108.     offset+=32;
  109.     sum = convertThirtyTwo(bp_dat);
  110.     outFile<<sum<<setw(25)<<"Number of Points"<<endl<<endl;
  111.     counter++;
  112.  
  113.  
  114.     if (sum >=1)
  115.  
  116.         tempsum = sum;
  117.  
  118.  
  119.         for ( j = 0; j<tempsum; j++)
  120.         {
  121.  
  122.             offset+=32;
  123.             sum = convertThirtyTwo(bp_dat);
  124.             outFile<<sum<<setw(25)<<"Latitude"<<endl<<endl;
  125.  
  126.             offset+=32;
  127.             sum = convertThirtyTwo(bp_dat);
  128.             outFile<<sum<<setw(25)<<"Longitude"<<endl<<endl;
  129.             counter++;
  130.  
  131.         }
  132.  
  133.  
  134. }
  135.  
  136.  
How can I store what is being printed out in a Structure or as an object.?
Jun 7 '07 #1
1 1605
weaknessforcats
9,208 Expert Mod 8TB
Use a stringstream.

Use the << operator you have to load the stringstream.

Then write an >> operator for your class or struct object and use the stringstream as the istream.

Here's one for a hypothetical Date object:
Expand|Select|Wrap|Line Numbers
  1. class Date
  2. {
  3.     private:
  4.        int month;
  5.        int day;
  6.        int year;
  7.     public:
  8.        friend istream& operator>>(istream& is, Date& dt);
  9. };
  10. istream& operator>>(istream& is, Date& dt)
  11. {
  12.     is >> dt.month >> dt.day >> dt.year
  13. }
  14.  
  15. int main()
  16. {
  17.    stringstream ss;
  18.    Date d;
  19.    ss << 7 << ' ' << 4 << ' ' << 1776 << endl;
  20.    ss >> d;
  21. }
  22.  
Remember to read back assumes you know the format of what was written. You may need field delimiters for playback.
Jun 8 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mark | last post by:
I have a website with an increasing amount of articles and news reports and so I am thinking of moving away from storing each article as a seperate page to having a single page and storing articles...
4
by: Brian Burgess | last post by:
Hi all, Anyone know of any special issues with storing cookies with ASP? I'm trying this with two browsers: One is IE 6.0 with cookies set to 'prompt'. This has been working properly as any...
6
by: Alfonso Morra | last post by:
I have written the following code, to test the concept of storing objects in a vector. I encounter two run time errors: 1). myClass gets destructed when pushed onto the vector 2). Prog throws a...
5
by: Don Vaillancourt | last post by:
I'm building a system when one can upload a document to the website. I will be storing the document on the hard-drive for quick/easy access, but I was also thinking of storing it in an existing...
6
by: bissatch | last post by:
Hi, I am currently writing a news admin system. I would like to add the ability to add images to each article. What I have always done in the past is uploaded (using a form) the image to a...
4
by: Rednelle | last post by:
Greetings all, As a newbie, using Access 2000, I would appreciate advice on the best way to include pictures. I have developed a 'Home Inventory' database which can include jpeg thumbnails of...
2
by: Robert Hanson | last post by:
I am new to the asp.net application building and I have read the information regarding the storing of information using session vs cookies vs viewstate. I am asking for suggestions/guidance as to...
6
by: (PeteCresswell) | last post by:
User wants to go this route instead of storing pointers in the DB and the documents outside. Only time I tried it was with only MS Word docs - and that was a loooong time ago - and it seemed to...
7
by: enrique | last post by:
i m in touch with c from last 1yr now just started data stucture in c and i have a problem in linear search and binary search if any one could explain with one example each thanks in advance
2
by: Mythran | last post by:
We followed an example found on MSDN to create an encrypted FormsAuthenticationTicket and storing the ticket in a cookie. Is this the "correct" way to store the authentication ticket? We are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...
0
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...

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.