noobish file create system

This is a discussion on noobish file create system within the C++ Programming forums, part of the General Programming Boards category; im trying to make a program that will output a spr.txt file to make it go like: admin forceclass 1 ...

  1. #1
    The N00b That Owns You!
    Join Date
    Jul 2005
    Location
    Canada!
    Posts
    178

    noobish file create system

    im trying to make a program that will output a spr.txt file to make it go like:

    admin forceclass 1 spr
    admin forceclass 2 spr
    admin forceclass 3 spr
    etc. up to 800 for a game
    im geting compile errors of sum sort with Dev-C++

    Code:
    #include <fstream>
    #include <iostream>
    
    using namespace std;
    
    char func() {
         int x
         for ( x = 1, x < 801, x++ ) {
               cout<<"admin forceclass "<< x <<" spr\n";
         }
    }
    
    int main()
    {
        cout<<"filesystem creation of spr.txt for americas army.";
        ofstream spr1 ( "spr.txt" );
        spr1>> func();
        spr1.close();
        cout<<"shud be made";
    }
    any help??

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,788
    You were missing several semicolons in various places. Also your output will not go to the file you are opening since you are writing to cout. Also, your function is not returning anything though it appears you want to return a char. You should also check that your file is open before you attempt to write to it. I would suggest this instead:

    Code:
    #include <fstream>
    #include <iostream>
    
    using namespace std;
    
    int main()
    {
        cout << "filesystem creation of spr.txt for americas army.";
        ofstream spr1 ( "spr.txt" );
    
        if( spr1.is_open() )
        {
            for( int i = 1; i < 801; ++i )
                spr1 << "admin forceclass " << i << " spr\n";
            cout << "\nshud be made";
        }
        
    
        return 0;
    }
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Work in Progress..... Jaken Veina's Avatar
    Join Date
    Mar 2005
    Location
    Missouri. Go Imos Pizza!
    Posts
    256
    Quote Originally Posted by C+noob
    Code:
    for ( x = 1, x < 801, x++ )
    I made this very same mistake when I was first starting out. Semicolons go between the three for statements, not commas. Commas would be used if you wanted to do something like this...
    Code:
    for(x = 1, y = 1; x < 801; ++x, ++y)
    Code:
    void function(void)
     {
      function();
     }

  4. #4
    The N00b That Owns You!
    Join Date
    Jul 2005
    Location
    Canada!
    Posts
    178
    i still get compiler errors like expecting primary sumthin before for im just wanting to get this!! GRR!

  5. #5
    The N00b That Owns You!
    Join Date
    Jul 2005
    Location
    Canada!
    Posts
    178
    WORKS thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 10:39 PM
  2. Can we have vector of vector?
    By ketu1 in forum C++ Programming
    Replies: 24
    Last Post: 01-03-2008, 04:02 AM
  3. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  4. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  5. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 03:30 PM

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