wierd error message

This is a discussion on wierd error message within the C++ Programming forums, part of the General Programming Boards category; Hi there everyone I'm trying to output an array to a text file but for some reason I keep getting ...

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    78

    wierd error message

    Hi there everyone I'm trying to output an array to a text file but for some reason I keep getting an error message. Would anyone have any advice
    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    class packunpack
    {
    private:
    	char lname[15];
    	char fname[15];
    	char email[36];
    	char stuid[15];
    	char buffer[65];
    	ofstream outfile("fixlength.txt");
    public:
    friend ostream& operator <<(ostream &stream, packunpack &p)
    { 
    	output<<p.buffer<<endl;
    	
    	return stream;
    }
    	 
    friend istream& operator >>(istream &stream, packunpack &p)
    	{
    	
    	char buffer[60];
    	char fixlng[5]={"    "};
    	
    	stream.getline(p.lname, 15, '\n');
    	strcpy(buffer, p.lname);
    	strcat(buffer, fixlng);
    	
    	stream.getline(p.fname, 15, '\n');
    	strcat(p.buffer, p.fname);
    	strcat(p.buffer, fixlng);
    	
    	stream.getline(p.stuid, 15, '\n');
    	strcat(p.buffer, p.stuid);
    	strcat(p.buffer, fixlng);
    
    	stream.getline(p.email, 35);
    	strcat(p.buffer, p.email);
        strcat(p.buffer, fixlng);
    	
    	cout << p;
        
    	return stream;
    	}
    };
     
    void main()
    {
    	
    	packunpack t;
    	fstream infile;
    	infile.open("f.txt", ios::in);
    	
    	while(!infile.eof())
    	{
    	infile >> t;
    	}
        infile.close();
    }
    Anyone have any idea whats going wrong here. I get error message
    error C2059 it says 'string' and that is it
    Last edited by drdodirty2002; 03-24-2005 at 10:44 PM.

  2. #2
    ---
    Join Date
    May 2004
    Posts
    1,379
    Well, knowing the error msg would make things simpler

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,340
    > ofstream outfile("fixlength.txt");
    My guess is it doesn't like instance information in a class declaration.

    > void main
    And everyone should object to this!
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. wierd struct error
    By sujeet1 in forum C Programming
    Replies: 5
    Last Post: 09-27-2007, 06:38 AM
  2. OpenGL Wierd **** - Order of Drawing Stuff?
    By Tonto in forum Game Programming
    Replies: 9
    Last Post: 11-09-2006, 08:56 PM
  3. Wierd chars...
    By mikahell in forum C++ Programming
    Replies: 8
    Last Post: 08-06-2006, 07:18 PM
  4. wierd errors
    By DeepFyre in forum C++ Programming
    Replies: 7
    Last Post: 12-21-2004, 08:32 PM
  5. This is wierd.
    By Ranedhel in forum C++ Programming
    Replies: 6
    Last Post: 12-12-2003, 02:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21