Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-19-2005, 06:39 AM   #1 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
File Reading!

Hi Everyone,

I am currently trying to read information from a text file. the information being read is shown below. How can i load diffrent Name & house data from the file by pressing the 'n' key on the keyboard.
  • Name
  • House

What ammendments do i need to make to the following code?

Many Thanks

Code:
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
#include <conio.h>
#include <dos.h>

int main (void)
{
  char name[50];
  int house[2];
  char choice;

  do
  {
  choice = 1;
    cin >> choice;

    ifstream data (".\\records.txt");
    data >> name;
    data >> house;
    cout << name;
    cout << house;
    data >> name;
    data >> house;
    data.close();
  } while (choice == 'n');
  delay(5000);
  return 0;
}
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 08-19-2005, 06:30 PM   #2 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
What do you exactly mean with:
"How can i load diffrent Name & house data from the file..."

And why is this an array?
int house[2];
__________________
Valmont is offline   Reply With Quote
Old 08-20-2005, 09:12 AM   #3 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
I want to load two pieces of information from a file. The aim is to load a diffrent name & house at one press of the 'n' key on the keyboard.

House is an array because it may store more than one character!

Many Thanks
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Old 08-20-2005, 11:39 AM   #4 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,544
Valmont is on a distinguished road
Oh come on I can't do anything with such an explanation. You want to load two pieces of info. What is that supposed to mean? And "House" does not store characters at all. It stores integers. Do you have the original assignment from your teacher? If so, post it so I can read it myself.
__________________
Valmont is offline   Reply With Quote
Old 08-20-2005, 01:03 PM   #5 (permalink)
Salchester
Salchester
 
Salchester's Avatar
 
Join Date: Jul 2005
Location: In a house
Posts: 230
Salchester is an unknown quantity at this point
3rd Time Lucky

As part of the functionality for a college assignment, I am trying to read two variables from a file. These being the following:
  • Name - this will store the persons name
  • House - this will store a house number

This is currently working, but i would like the user to load another name & house number that is stored within the file, upon pressing the ‘n’ key on their computer’s keyboard.

How can this be done?
See coding so far below.

Many Thanks

Code:
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
#include <conio.h>
#include <dos.h>

int main (void)
{
  char name[50];
  int house[2];
  char choice;

  do
  {
    choice = 1;
    cin >> choice;

    ifstream data (".\\records.txt");
    data >> name;
    data >> house;
    cout << name;
    cout << house;
    data >> name;
    data >> house;
    data.close();
  } while (choice == 'n');
  delay(5000);
  return 0;
}
__________________
Many Thanks, in advance!

Salchester.
The Future Is Here - Are You Ready?
Salchester is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
text file recursive string reading C toblerone Standard C, C++ 4 08-04-2004 10:05 PM
Reading in a file jello Standard C, C++ 4 05-04-2004 07:53 AM
Binary I/O file reading (0x1a trouble) Danish Standard C, C++ 2 05-26-2003 10:02 AM


All times are GMT -8. The time now is 09:07 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting