Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

C++ help required

  • 08-03-2010 9:39pm
    #1
    Registered Users, Registered Users 2 Posts: 112 ✭✭


    Hi guys I need some help, I'm back in college and not having done programing for 9 years I have totally forgot what I'm doing.

    I need to write a header file and a main.cpp file. Needs to have class which opens a text file, numbers all the lines and saves it again under my own name.

    Sounds easy but I'm totally lost.

    Thanks a lot..


Comments

  • Registered Users, Registered Users 2 Posts: 8,493 ✭✭✭RedXIV


    What in particular is stopping you?

    This is a good link to get you started


  • Registered Users, Registered Users 2 Posts: 112 ✭✭beatman91


    Thanks I've seen this, its a really good site.

    Well three things, firstly thats all written in the main and thats the way I use to do it in C but I just can't get how you would write it in the header file. And the other is how would you number each line, I sure there isin't a command for this, I can't even see how a loop would do this.

    and finally any idea which command saves the file?

    I use to like machine code back in the day but this is just beyond me.


  • Registered Users, Registered Users 2 Posts: 26,584 ✭✭✭✭Creamy Goodness


    i would use a while loop to loop through the file reading in each line as you loop.

    then pre-pend a number to the start of each line. then write that line back to the file, then increment that number for the next loop iteration.

    the above is probably not the most efficient method but it's the simplest.

    show us what you've got so far, we'll help you more if you show an effort.


  • Registered Users, Registered Users 2 Posts: 112 ✭✭beatman91


    here is what I have so far but as you can tell it does not work so any help would be great.

    #include <iostream>
    #include <fstream>

    using namespace std;

    int main()
    {
    char inputfile [100];
    cout <<"Type File Path :"<<endl;
    cin >> inputfile;

    ifstream infile;
    ofstream outfile;


    inputfile.open(inputFile);

    if(outfile.is_open()){
    cout<<"output File is open"<<endl;
    outfile.close();
    }
    else{
    cout<<"error"<<endl;
    }
    infile.open ("name.txt", ofstream::out | ofstream::app);

    while(){

    outfile<<""; //this is the part I needs to number each line

    outfile.open("outputfile.dat");

    outfile.close();
    infile.close();

    return 0;
    }


  • Registered Users, Registered Users 2 Posts: 112 ✭✭beatman91


    ok I figured it out


  • Advertisement
Advertisement