Thread: Write to file

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    241

    Write to file

    Hello, I finally wrote a usefull peice of code for something that I am doing, I was going to have to type in over 3000 ports if i didnt know how to code so it took me 5 minutes to write a code for it but i just found out I cant copy from the command prompt so i need to know how can I mod this code to write to a file?
    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
        int PortNumberBig;
        
        cout<<"3658,6667,6668,6669,";
        PortNumberBig=40000;
        while(PortNumberBig<43000)
        {
            cout<<PortNumberBig<<",";
            PortNumberBig++;
        }
        cout<<"45000,45001";
        cin.get();
        return 0;
    }
    Isnt it pretty lol

    EDIT:
    Got it I think
    Code:
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    int main()
    {
        int PortNumberBig;
        
        ofstream a_file("Ports.txt");
        
        a_file<<"3658,6667,6668,6669,";
        PortNumberBig=40000;
        while(PortNumberBig<43000)
        {
            a_file<<PortNumberBig<<",";
            PortNumberBig++;
        }
        a_file<<"45000,45001";
        a_file.close();
        cin.get();
        return 0;
    }
    Pretty.
    Last edited by bikr692002; 03-04-2006 at 11:53 PM.

  2. #2
    Been here, done that.
    Join Date
    May 2003
    Posts
    1,164
    I'm glad you got it cuz it was difficult to read your post using puntuation really lets others understand what you are trying to say without it it is very hard to decipher what you said because sentences are necessary for understanding hope this helps in the future.
    Definition: Politics -- Latin, from
    poly meaning many and
    tics meaning blood sucking parasites
    -- Tom Smothers

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. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Encryption program
    By zeiffelz in forum C Programming
    Replies: 1
    Last Post: 06-15-2005, 03:39 AM
  5. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM