Thread: Simple word processor.

  1. #1
    Registered User
    Join Date
    Feb 2010

    Question Simple word processor.

    Im a novice in the C++ programming language and ive been using the book C++ Without Fear to help myself get a grip on the language. One of the activities in the book is writing a Word processor "like" program.
    What I'd like to do is write it so that the user doesn't have to enter a preexisting file name to begin. I'd like to have the program create a file with the name the user inputs and save it to a Folder that exists already.
    Also I'm sure this is much more complicated to do but later on I'd like to be able to add a feature where it will print what you input when your done. Any tips on how to accomplish this would be appreciated...sorry i didnt think about defining print but yes i meant onto physical paper. As it turns out your right it will create the file i just didnt know it. o.o

    #include <iostream>
    #include <fstream>
    using namespace std;
    int main() {
        char filename[81];
        char input_line[81];  // Input line for text entry
        cout << "Enter a file name and press ENTER: ";
        cin.getline(filename, 80);
        ofstream file_out(filename);
        if (! file_out) {
            cout << "File " << filename << " could not be opened."; //if file opening fails
            return -1;
        cout << "File " << filename << " was opened." << endl;
        while (1) {
            cout << "Enter line (~~~ to quit)>>";
            cin.getline(input_line, 80);
            if (strcmp(input_line, "~~~") == 0)
            file_out << input_line << endl;
        return 0;
    Last edited by martin94; 02-11-2010 at 09:04 PM.

  2. #2
    Not stupid, just stupider yaya's Avatar
    Join Date
    May 2007

    Thumbs up

    From a quick look at your code, it seems that it should already create a new file if it doesn't exist already.
    When you say print, do you mean onto the screen, or onto physical paper? Assuming you meant the paper, this (to my knowledge) is platform specific. If you're on windows, I know the win32 API has functions that does this. Check MSDN if you're really keen, though it may not be as simple as you think.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Perhaps consider an edit class with member functions like
    - load file
    - save file
    - insert line
    - delete line
    - ditto for characters.
    - other methods you can think of.

    This implements the model
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Feb 2010
    @Salem Yea i was thinking about doing some stuff like that but i think its probably beyond my capabilities for now at least. Also im new here and was wondering is there a double posting rule?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A certain type of word processor
    By Cielo in forum Tech Board
    Replies: 1
    Last Post: 11-30-2007, 01:07 PM
  2. please help with binary tree, urgent.
    By slickestting in forum C Programming
    Replies: 2
    Last Post: 07-22-2007, 07:55 PM
  3. finding strings in strings
    By watshamacalit in forum C Programming
    Replies: 14
    Last Post: 01-11-2003, 01:08 AM

Tags for this Thread