Text editor

This is a discussion on Text editor within the C++ Programming forums, part of the General Programming Boards category; please explain it to me as i am very new to c++....

  1. #16
    Registered User L_U_K_E's Avatar
    Join Date
    Apr 2006
    Posts
    106
    please explain it to me as i am very new to c++.

  2. #17
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Which part do you mean? Well for my string thing say they entered the first part of "example.txt" and the input typed was example then you would use:
    Code:
    stringx += ".txt
    So basically you add teh file extension to the end.

    And for progbman:

    Code:
    ofstream a_file ( stringx.c_str() );
    Last edited by bumfluff; 04-28-2006 at 02:37 PM.

  3. #18
    Registered User L_U_K_E's Avatar
    Join Date
    Apr 2006
    Posts
    106
    ive just tryed both but i just cant get them to work.

  4. #19
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Maybe you should post your code.

  5. #20
    Registered User L_U_K_E's Avatar
    Join Date
    Apr 2006
    Posts
    106
    Code:
    #include <iostream>
    #include <fstream>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    int main()
    {
        string a;
        string b;
        string str;
        string x;
        
        cout<<"Please verify what the file name should be: ";
        cin>>x;
        cin.ignore(); 
        ofstream a_file ( string x.c_str()ios::app);
        cout<<"Please input some text.\n";
        cout<<">";
        getline(cin,a);
        cin.ignore();
        a_file<< a;
        a_file.close();
        ifstream b_file("str.txt");
        cout<<"File opened successfully.\n";
        cout<<"Reading Data from File."<<"\n";
    	cout<<setfill('-')<<setw(80)<<"-"<<endl;
    	b_file.close();
        cin.get();
    }

  6. #21
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    What are you trying to do as there isn't really any point to that code.

  7. #22
    Registered User L_U_K_E's Avatar
    Join Date
    Apr 2006
    Posts
    106
    No probs it got it sorted

  8. #23
    Registered User L_U_K_E's Avatar
    Join Date
    Apr 2006
    Posts
    106
    Now im just having probs getting it to read the file.Any ideas?

  9. #24
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Have you made sure that the file is opne...checkout the tutorial and are you usiong << instead of >>

  10. #25
    Registered User L_U_K_E's Avatar
    Join Date
    Apr 2006
    Posts
    106
    1."Have you made sure the file is open".
    A. Yes.

    2."are you using << instead of >>".
    A. I am using >> it just closes as soon as it gets to that point in the prog.

  11. #26
    Registered User L_U_K_E's Avatar
    Join Date
    Apr 2006
    Posts
    106
    I ave made some progress but as soon as it gets to whitespace it stops and will only print the first word. It should be printing "This is a test file" but its just printing "This" i am using getline, so whats up?

  12. #27
    Registered User L_U_K_E's Avatar
    Join Date
    Apr 2006
    Posts
    106
    + i cant now append to the end of the text if the user defines the name of the file, i just get an error message.

  13. #28
    Registered User
    Join Date
    Apr 2005
    Posts
    76
    post any new code up

  14. #29
    Registered User L_U_K_E's Avatar
    Join Date
    Apr 2006
    Posts
    106
    Code:
    #include <iostream>
    #include <fstream>
    #include <iomanip>
    #include <string>
    
    using namespace std;
    
    int main()
    {
        cout<<"Please enter a filename: ";
        getline(cin,x);
        ofstream a_file (x.c_str());
        cout<<"Please input some text.\n";
        cout<<">";
        getline(cin,a);
        cin.ignore();
        a_file<< a;
        a_file.close();
        ifstream b_file( x.c_str());
        cout<<"File opened successfully.\n";
        cout<<"Reading Data from File."<<"\n";
    	cout<<setfill('-')<<setw(80)<<"-"<<endl;
        getline(cin, b);
    	cin.ignore();
    	b_file>> b;
    	cout<< b <<"\n";
    	b_file.close();
        cin.get();
    }

  15. #30
    Registered User L_U_K_E's Avatar
    Join Date
    Apr 2006
    Posts
    106
    I made a few changes to it and it works now so no worrys.Thanx though.

Page 2 of 4 FirstFirst 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