another noob program

This is a discussion on another noob program within the C++ Programming forums, part of the General Programming Boards category; when i compile this, i get many errors, and i dont know what any of them mean any help?, im ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    266

    another noob program

    when i compile this, i get many errors, and i dont know what any of them mean

    any help?, im just doing this program for experience

    NVM, it works now ----
    Code:
    // file opener, supposed to ask you if you want to 
    //append or clear  and start over
    
    #include <iostream>
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
    	int toggle;
    	string editORnew,thewordnew;
    	string filename;
    	thewordnew = "new";
    	cout << "whats the file? include extenstion \n";
    	cin >> filename;
    	cin.ignore();
    	ofstream a_file (filename.c_str(), ios::app);
    	if(!a_file.is_open())
    	{
    		cout << "File couldnt be opened";
    	}
    	else
    	{
    		cout << "file opened \nedit or new?";
    	    cin >> editORnew;
    		if(editORnew == thewordnew)
    		{
    			a_file.close();
    			ofstream b_file (filename.c_str());
    			toggle = 1;
    							if(toggle ==1)
    							{		
    								if(!b_file.is_open())
    								{
    								cout << "\nFile unopenable";
    								}
    							}
    		}
    			else
    			{
    			cout << "\n ok, editing file.";
    			}
    		
    				
    			
    	}
    
    	if(toggle != 0)
    	{
    		cout << "\n ok, starting file over.";
    	}
    return 0;
    }
    Last edited by rodrigorules; 11-26-2005 at 08:56 PM.

  2. #2
    Bond sunnypalsingh's Avatar
    Join Date
    Oct 2005
    Posts
    162
    U need to include <string>.....check the if conditions, brackets are misplaced....and many other things

  3. #3
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    You use strings without “ #include <string> “.

    You can not use a string to open a file. I will not go into details why, look it up.
    You can use char arrays or you can convert it to a cstring (char array) very easily with.
    Code:
    	ofstream a_file (filename.c_str(), ios::app); //open file - o is for open
    You also need to add the .c_str() to your other ostream.

    Main needs to return something, preferably 0 for success.
    Put “ return 0; “ before your last } (the end of the main function)

    That is what is wrong technically with your program.
    Last edited by Enahs; 11-26-2005 at 08:47 PM.

  4. #4
    Registered User
    Join Date
    Aug 2005
    Posts
    266
    got it to compile
    Last edited by rodrigorules; 11-26-2005 at 08:55 PM.

  5. #5
    Registered User CompiledMonkey's Avatar
    Join Date
    Feb 2002
    Location
    Richmond, VA
    Posts
    438
    Might want to start out with a more simplistic example if you're trying to learn this stuff.

  6. #6
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    I would say generally it is not best to go back and edit your original post and fix the problems once someone has helped you figure them out. This board has a good search feature and it is for helping people; and learning from other peoples mistakes is great help.

    Just my opinion…I dunno what the “official” policy is though….

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    266
    k, i wont do it again

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 10:17 PM
  3. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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