473,569 Members | 2,880 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File stream

9 New Member
Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. #include<iomanip>
  3. #include<fstream>
  4. using namespace std;
  5.  
  6.  
  7.  
  8. struct info_struct
  9. {
  10.     char ID[5];
  11.     int number_year;
  12.     int number_CD;
  13. };
  14.  
  15.  
  16.  
  17. void Display(info_struct[], int);
  18. void Passing(info_struct[], int);
  19.  
  20. int main()
  21. {
  22.     char select;
  23.     cout << setprecision(2)
  24.         << setiosflags(ios::fixed)
  25.         << setiosflags(ios::showpoint);
  26.  
  27.  
  28.  
  29.     info_struct info[4] = 
  30.     {{"M123" , 2, 3},
  31.     {"M225", 1, 6},
  32.     {"M248", 2, 1},
  33.     {"M552", 3, 5}};
  34.     do
  35.     {
  36.  
  37.     cout << "Mr. Muzik's Fanatastic Music Club\n";
  38.     cout << "==================================\n";
  39.     cout << "A - Display Annual Report\n";
  40.     cout << "B - Input Information\n";
  41.     cout << "Please make a selection: ";
  42.     cin >> select;
  43.  
  44.     switch(select)
  45.     {
  46.     case 'A':
  47.     case 'a':
  48.  
  49.  
  50.              Display(info, 4);
  51.  
  52.         break;
  53.  
  54.             Passing(info, 4);
  55.  
  56.     case 'B':
  57.     case 'b':
  58.  
  59.  
  60.         break;
  61.     default:
  62.         cout << endl << endl
  63.             << "Invalid Property Code! Try again.\n" << endl;
  64.         break;
  65.  
  66.  
  67.     }
  68.     }while((select != 'a' || select != 'A') && (select != 'B' || select != 'b'));
  69.     return 0;
  70. }
  71.  
  72.  
  73. void Display(info_struct NEW[], int size)
  74. {
  75.             int i;
  76.             cout << endl << endl;
  77.         cout << setw(20)<< "ID" 
  78.              << setw(20) << "Number of Year"
  79.              << setw(20) << "Number of CD bought"  << endl;
  80.  
  81.             for (i = 0; i < size; ++i)
  82.             {
  83.                 cout << endl;
  84.                 cout << setw(20)<< NEW[i].ID 
  85.                      << setw(20)<< NEW[i].number_year 
  86.                      << setw(20)<< NEW[i].number_CD  << endl;
  87.             }
  88. }
  89. void Passing(info_struct NEW_2, int size_2)
  90.  
  91. {
  92.     int row;
  93.  
  94.     cout << endl;
  95.     cout << "Enter the table values: "
  96.         <<endl << endl;
  97.     for(row = 0; row < size_2; ++row)
  98.     {
  99.         cout << endl;
  100.  
  101.         cout << "ID Number: ";
  102.         cin.getline(NEW_2[row].ID, 5);
  103.  
  104.         cout << "Number of Year: ";
  105.         cin >> NEW_2[row].number_year;
  106.  
  107.         cout << "Number of CD bought: ";
  108.         cin >> NEW_2[row].number_CD;
  109.  
  110.         cin.get();
  111.     }
  112. }

I am a bit confused on why it doesnt work I am trying to have it enter the information, from the void. I guess I want to make the stucture interactive inside or outside the main?
Apr 28 '08 #1
4 1375
Savage
1,764 Recognized Expert Top Contributor
What errors are you getting?

Also take a good look at this:

Expand|Select|Wrap|Line Numbers
  1. case 'A':
  2. case 'a':
  3.  
  4.  Display(info, 4);
  5.  break;
  6.  
  7. Passing(info, 4);
  8.  
  9. case 'B':
  10. case 'b':

And please use code tags around your code.(Select your code and press # button,you can also specify a language e.g[code=C] will use C markings)

Savage
Apr 28 '08 #2
Learner21
9 New Member
Thanks a whole bunch I was just curious:
On my passing structure whenever the user types in more then 2 values the whole program loops:
Expand|Select|Wrap|Line Numbers
  1. void Passing(info_struct NEW_2[], int size_2)
  2.  
  3. {
  4.     int row; 
  5.     cout << endl;
  6.     cout << "Enter the table values: "
  7.         << endl << endl;
  8.     for(row = 0; row < size_2; ++row)
  9.     {
  10.         cout << endl;
  11.  
  12.         cout << "ID Number: ";
  13.         cin.getline(NEW_2[row].ID, 4);
  14.  
  15.         cout << "Number of Year: ";
  16.         cin >> NEW_2[row].number_year;
  17.  
  18.         cout << "Number of CD bought: ";
  19.         cin >> NEW_2[row].number_CD;
  20.  
  21.         cin.get();
  22.     }
  23. }
  24.  
I hope I placed in the code tags right. I thought if I had that number 4 it wouldnt matter. I try adding a do while but it ended looping the number of year and CD I am still working on it I just wish I knew what I should do.
Apr 28 '08 #3
Savage
1,764 Recognized Expert Top Contributor
I believe that solution to your problem lies in this thread
Apr 28 '08 #4
Learner21
9 New Member
I believe that solution to your problem lies in this thread
Thank you for your help and patience
Apr 29 '08 #5

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

Similar topics

6
1765
by: Siddharth Taneja | last post by:
Hi, I have a very simple prg over here, trying to read the lines of a file #include <iostream> #include <fstream> #include <iostream> #include <string> using namespace std;
2
13081
by: gnv | last post by:
Hi all, I am writing a cross-browser(i.e. 6 and netscape 7.1) javascript program to save an XML file to local file system. I have an xml string like below: var xmlStr = "<?xml version="1.0" encoding="UTF-8"?><a>some info</a>"; I want to save this xml file to local file system with JavaScript,
19
3205
by: Johnny Google | last post by:
Here is an example of the type of data from a file I will have: Apple,4322,3435,4653,6543,4652 Banana,6934,5423,6753,6531 Carrot,3454,4534,3434,1111,9120,5453 Cheese,4411,5522,6622,6641 The first position is the info (the product) I want to retreive for the corresponding code. Assuming that the codes are unique for each product and all...
13
4289
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming that this is suppossed to end up as a component for others to use, and therefore I do NOT have access to their global.cs::Session_End() how do I...
5
3042
by: Daniel Corbett | last post by:
I am trying to save a file dynamically created in a webpage. I get the following headers, but cannot figure out how to save the attachment. I am basically trying to replicate what internet explorer would do in this case. The headers I am getting are: Headers {Content-Disposition: attachment; filename="dynamic_file.mdb" Connection:...
5
3156
by: IcingDeath via DotNetMonster.com | last post by:
I am building this SQL Server database app in which i can store files. In order to display files I want to have the app show the associated icon for the extension of the file that is in the database. Therefore the file doesnt really exist on the user's hard drive. All the file extracting techniques require that I have the actual file on the...
4
2494
by: rony_16 | last post by:
Hi, I have a program that connects to a site With WebRequest and WebResponse . The response of this site is a file (csv file). The problem is that the file do not comes as a stream , hi is a part of the header (Content-Disposition:attachment; filename=changehistory.csv) i tried to download this file as a stream , but it do not work . i...
5
64606
AdrianH
by: AdrianH | last post by:
Assumptions I am assuming that you know or are capable of looking up the functions I am to describe here and have some remedial understanding of C++ programming. FYI Although I have called this article “How to Parse a File in C++”, we are actually mostly lexing a file which is the breaking down of a stream in to its component parts,...
6
17108
by: J055 | last post by:
Hi I have the following code. I upload an XML file using the FileUpload object, store the stream in a session so the user gets the chance to confirm some options then pass the stream from the Session to an XmlReader. if (performImport == false) { Session = fileUpload1.FileContent; //... some other code
45
4389
by: Dennis | last post by:
Hi, I have a text file that contents a list of email addresses like this: "foo@yahoo.com" "tom@hotmail.com" "jerry@gmail.com" "tommy@apple.com" I like to
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7619
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7930
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7681
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.