Text editor

This is a discussion on Text editor within the C++ Programming forums, part of the General Programming Boards category; [i am new to c++] I am making a text editor that will open a file and output what the ...

  1. #1
    Registered User L_U_K_E's Avatar
    Join Date
    Apr 2006
    Posts
    106

    Text editor

    [i am new to c++] I am making a text editor that will open a file and output what the person types into a .txt file. So far i have a prog that will open a file but how do i get the input and output it into the file?

  2. #2
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    www.cprogramming.com there is a very good tutorial on file input and output.

  3. #3
    Registered User L_U_K_E's Avatar
    Join Date
    Apr 2006
    Posts
    106
    Okm so i got the file i/o sorted but now when it outputs the text into a .txt file it just outputs the 1st word the user inputs.

  4. #4
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    use getline()

    check www.cppreference.com how to use it.
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  5. #5
    Registered User L_U_K_E's Avatar
    Join Date
    Apr 2006
    Posts
    106
    I just tried that getline() but all that i get is a bunch of numbers e.g. 0x443468.

  6. #6
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    getline(cin, stringname);

    Ok after looking at the web page that is what it shows you to do...post your code.
    Last edited by bumfluff; 04-28-2006 at 10:39 AM.

  7. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Have you got #include <string>

  8. #8
    Registered User L_U_K_E's Avatar
    Join Date
    Apr 2006
    Posts
    106

    Question

    i tried it with the #include <string> still didn't work(still got numbers).
    Last edited by L_U_K_E; 04-28-2006 at 10:49 AM.

  9. #9
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Post your code....

    It is really the only quick way of getting help.

  10. #10
    Registered User L_U_K_E's Avatar
    Join Date
    Apr 2006
    Posts
    106
    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
        char str[100];
        string s;
        
        ofstream a_file ("LW_Text.txt", ios::app);
        cout<<"Please input some text.\n";
        cout<<">";
        getline(cin,s);
        cin.ignore();
        a_file<<getline(cin,s);
        a_file.close();
        cin.get();
    }

  11. #11
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    
    using namespace std;
    
    int main()
    {
        string s;                              //your char string was redundant here
        
        ofstream a_file ("LW_Text.txt", ios::app);
        cout<<"Please input some text.\n";
        cout<<">";
        getline(cin,s);
        cin.ignore();
        a_file<<s;                           //you don't need getline here
        a_file.close();
        cin.get();
    }
    Try that...it works for me now.

  12. #12
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Now try making it able to read the txt file.

    And possibly make the user able to choose the name of the file.

  13. #13
    Registered User L_U_K_E's Avatar
    Join Date
    Apr 2006
    Posts
    106
    How could i make the user specify the name of the file?

  14. #14
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,805
    By having the user enter the file name on a prompt and you saving it as a string and then opening a file based on what they wanted. Just remeber c_str().
    Woop?

  15. #15
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    And if they only want to enter the first part of the file name then you could use string name += ".txt"

Page 1 of 4 1234 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. creating very simple text editor using c
    By if13121 in forum C Programming
    Replies: 9
    Last Post: 10-19-2010, 05:26 PM
  2. C++ For Text Editor?
    By bmroyer in forum C++ Programming
    Replies: 12
    Last Post: 04-05-2005, 02:17 AM
  3. struct question
    By caduardo21 in forum Windows Programming
    Replies: 5
    Last Post: 01-31-2005, 03:49 PM
  4. help about text editor
    By nag in forum C++ Programming
    Replies: 2
    Last Post: 04-24-2003, 11:45 AM
  5. Making a text editor
    By neandrake in forum C++ Programming
    Replies: 5
    Last Post: 02-26-2002, 10:43 PM

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