Thread: Need to report some things in a text file to the user...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    13

    Need to report some things in a text file to the user...

    I need to make a program that asks a user for the name of a text file and reports the number of characters in the text file, and the number of end-of-line characters in the text file. I made a text file called TEXT.txt. I am really completely lost right now...I really don't have anything that makes much sense now, but here it is. Please help me. Thanks.

    Code:
    #include<iostream.h>
    #include<fstream.h>
    
    int main()
    {
    	ifstream textfile;
    	cout << "Enter the name of a text file: ";
    	cin >> textfile;
    
    	textfile.open(textfile, ios::in)
    
    	while(!textfile.eof())
    	{
    
    	return 0;
    }

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Be a lot more specific in future. Tell us what errors you're getting, what the program is doing, what you'd like to do, what you've tried, etc...

    Code:
    #include<iostream>
    #include<fstream>
    
    using namespace std;
    Technically the top of your program should look like that - they changed stuff a bit in the latest C++ standard. Older compilers will still use the old style, but I strongly recommend that you update to a new one (Dev-C++ 5.0 beta is great - www.bloodshed.net).

    Make sure you're using ifstream's properly - it's been a while since I did it myself but the parameter list in
    Code:
    textfile.open(textfile, ios::in)
    just doesn't look right to me. Not to mention that you're missing a semicolon at the end of that line.

    And then your program is incomplete. Your while loop has an opening {, never matches it with a closing one, and does nothing.

  3. #3
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Code:
    int x = 0;
    
    while (!textfile.eof())
    {
        char garb;
        textfile.get(garb);
        x++;
    }
    
    x = x-1;
    
    cout << x;
    There's one loop. See what you can do with it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 05:02 AM
  3. How to use FTP?
    By maxorator in forum C++ Programming
    Replies: 8
    Last Post: 11-04-2005, 03:17 PM
  4. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  5. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM