1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

disapearing program

Discussion in 'C++' started by johanjohan, Aug 23, 2007.

  1. johanjohan

    johanjohan New Member

    Joined:
    Aug 19, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    I know this is pretty basic stuff, but Im having a problem with this program. It keeps dispearing off the screen with out finishing

    It disapears after i enter the name of out_file_name

    I have system("pause") at the end because im using a dev compiler and if that pause isnt put ther the program will run real fast and disapear off the screen. the system ("pause") prevents that.

    thank you
    Code:
    #include < fstream>
    #include<iostream>
    #include <cstdlib>
    int main()
    {
    using namespace std;
       char in_file_name[16], out_file_name [16];
       ifstream in_stream;
       ofstream out_stream;
    
    cout << "I will sum six numbers taken from input\n"
         << "file and write the sum to an output file.\n";
    cout << "Enter the input file name (maximum of 15 characters): \n";
    cin >> in_file_name;
    cout<< "Enter the output file name (maximum of 15 characters): ";
    cin >> out_file_name;
    
    // its right here that the program disapears off the screen
    
    cout << "I will read numbers from the file"
         <<  in_file_name << "and\n"
         << "place the sum in the file\n"
         <<  out_file_name <<endl;
         
    in_stream.open(in_file_name);
    if (in_stream.fail())
    {
         cout << "Input file opening failed.\n";
         exit(1);
    }
    out_stream.open(out_file_name);
    if (out_stream.fail())
    {
          cout << "Output file opening failed.\n";
          exit(1);
    }
    int first, second, third, fourth, fifth, sixth;
    in_stream >> first >> second >> third >> fourth >> fifth >> sixth;
    out_stream << "The sum of the first 3\n"
               <<"numbers in" << in_file_name << endl
               << "is" <<(first+second+third+fourth+fifth+sixth)
               << endl;
               
    in_stream.close();
    out_stream.close();
    
    cout <<"end of program.\n";
    system("pause");
    return 0;
    }
     
    Last edited by a moderator: Aug 24, 2007
  2. johanjohan

    johanjohan New Member

    Joined:
    Aug 19, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    I want to change this program from doing numbers to doing letters and character (%, *, \ )
    to do word counts in any file. to see how many times a certain word or character is in a file. Im not looking for it to find it where its at in the file, I just want to have it count.

    thanks
     
  3. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    I don't really think you would move into a community, attend the church, and fart loudly during the sermon. You would probably wait until you had determined that was the norm for that community. Surely you could accord us the same courtesy.

    Check out the community.
     
  4. johanjohan

    johanjohan New Member

    Joined:
    Aug 19, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    wow, you got to be kidding
     
  5. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Nope, I'm not kidding at all. I'm encountered lots of dummies in 66 years, and I'm sure you will too. You move in here, ask for free help, but don't even bother to read the "Before you make a query" thread. It makes me think you're probably still hanging onto your mama's tit for free meals. If you're one of those more and more commonly encountered people who think they are born entitled, perhaps you should read some Eric Raymond.
     
  6. johanjohan

    johanjohan New Member

    Joined:
    Aug 19, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    whats with all the degrading?
     
  7. johanjohan

    johanjohan New Member

    Joined:
    Aug 19, 2007
    Messages:
    15
    Likes Received:
    0
    Trophy Points:
    0
    can someone please help me with this program

    thank you
     
  8. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    You need to have some user input before the program exits through main or exit function and that should solve the problem.
     
  9. seeguna

    seeguna New Member

    Joined:
    Jun 20, 2007
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Technical Consultant
    Location:
    Chennai
    Ur program works well in MS Vc++ 6 compiler..........
     
  10. DaWei

    DaWei New Member

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    Unfortunately, programs are rarely launched by using a compiler, much less VC++ 6.0, which is now ten years old. Programs typically run until they are done, then exit. If one wants them to wait for user input to exit, then one asks for user input, whether that be a "Press Enter" or a button or the big X in the upper-right corner, or whatever.
     

Share This Page