Thread: Question on use of classes

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    10

    Question on use of classes

    Hello all. I have a very simple exercise to do. On notepad, I create a file called filelab.txt. The only thing in this file is the sentence "C++ is fun" (without the quotes, just the sentence). So what I'm supposed to do is: Read in each letter(from the file) separately, and then display (on the screen) as it is read in from the file, stopping at "n".
    2 conditions:
    1) Do not use a loop to read.
    2) I must use classes.

    I have finished this problem, and it works fine, but without classes. I'm not really sure how to do it with classes.
    Here's the code:
    Code:
    #include <fstream.h>
    #include <stdlib.h>
    #include <stdio.h>
    
    
    int main ()
    {
    	ifstream infile("A:filelab.txt", ios::nocreate); //this opens up the file
    	char a, b, c, d, e, f, g, h;
    	infile >> a;
            cout << a << endl;
    	infile >> b;
            cout << b << endl;
    	infile >> c;
            cout << c << endl;
    	infile >> d;
            cout << d << endl;
            infile >> e;
    	cout << e << endl;
    	infile >> f;
    	cout << f << endl;
    	infile >> g;
    	cout << g << endl;
    	infile >> h;
    	cout << h<< endl;
    	
    	infile.close();
    	return 0;
    
    }
    now my questions are:
    1) Where would the "ifstream infile("A:filelab.txt", ios::nocreate); //this opens up the file " command go, in the source file? I don't think it goes in the main or the header file, but not sure.
    2)What is the class of? All the program does is read a sentence from a file, and output to screen. So what is the class about in this case, the sentence? I'm having a hard time with this, what's the class, the object, in the problem?

    Thanks for any feedback!
    Last edited by Flyer; 06-23-2003 at 05:38 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Classes question...
    By Raigne in forum C++ Programming
    Replies: 24
    Last Post: 09-12-2006, 01:46 AM
  2. Replies: 2
    Last Post: 07-28-2006, 02:59 PM
  3. Simple Question about Classes
    By Loctan in forum C++ Programming
    Replies: 5
    Last Post: 06-26-2006, 02:40 AM
  4. Classes and Win32 API, and another Question
    By philvaira in forum Windows Programming
    Replies: 10
    Last Post: 04-10-2004, 07:21 PM
  5. Newbie question about the Private type in classes
    By Ryeguy457 in forum C++ Programming
    Replies: 1
    Last Post: 09-07-2002, 10:17 PM