Thread: ever just wanna bang your head against the desk?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    6

    Unhappy ever just wanna bang your head against the desk?


    Okay the idea is to have the user choose 1 of 4 potential slots. The files do exist on the hard drive in the correct directory as 1.txt, 2.txt, 3.txt and 4.txt. All I want to do is let the user select which file to edit, type in a message, and have the program write to that file.

    The program compiles and runs fine, but its not doing, what looks to me, like an obvious routine even a laymen (me) couldnt screw up. I understand that i havent included 2-4 in the selection process yet, and thats because all this does is prompt for a choice, displays "Enter a message:" and then abruptly exits. getline() isn't coming up to let me type in the message.

    This can't be that hard! What the crap?

    Code:
    #include <fstream>
    #include <iostream>
    #include <string>
    #include <cstdlib> // For EXIT_FAILURE, EXIT_SUCCESS
    
    using namespace std;
    
    int main()
    {
        string message;
        int slot;
        //create a name for the file
        cout << "Select a slot:" << endl;
        cout << "1 | 2 | 3 | 4" << endl;
        cin >> slot;       
            
        if(slot == 1) {
        ofstream SaveFile("1.txt",ios::out|ios::app);
        // Get message from user
        cout << "Enter a message: " ;
        getline(cin,message);
        // Write/append message to end of file
        SaveFile << message << endl;
        }
    // else system("pause");
    return EXIT_SUCCESS;
    }
    Last edited by osiris_99; 02-22-2005 at 03:42 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. question about a working linked list
    By cold_dog in forum C++ Programming
    Replies: 23
    Last Post: 09-13-2006, 01:00 AM
  3. Can't figure out problem with code
    By Beast() in forum C Programming
    Replies: 4
    Last Post: 04-16-2005, 05:27 PM
  4. Linked List Help
    By Perverse in forum C++ Programming
    Replies: 3
    Last Post: 02-22-2005, 08:33 AM
  5. GIvE iT tO mE NOwWwwWww bABy!!!!!!!! wooooooooo
    By Xterria in forum Party Board
    Replies: 12
    Last Post: 07-14-2003, 07:03 AM