I need help with saving inputted text to a file.

This is a discussion on I need help with saving inputted text to a file. within the C++ Programming forums, part of the General Programming Boards category; I'm making a DOS text editor (Yeah i know, dumb idea.) but I cant get the outputted file to display ...

  1. #1
    Seven years? civix's Avatar
    Join Date
    Jul 2002
    Posts
    605

    I need help with saving inputted text to a file.

    I'm making a DOS text editor (Yeah i know, dumb idea.) but I cant get the outputted file to display the whole of what the user inputted.

    It can't be ultimate.h being included, because it will compile if I
    remove the "string variable;" line.

    Thanks in advance for any help!

    Code:
     #include "ultimate.h"
     using namespace std;
     string variable;
    int main()
    {
    HANDLE hStdout;
    hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
        SetConsoleTextAttribute(hStdout, BACKGROUND_BLUE);
        cout<<"                       ---[The Civic Wordedit]---                           _ X"<<endl;
        textcolor(LIGHTGRAY);
        char variable;
    cin >>	variable;
    	ofstream fout;                           // this means tha fout acts for ofstream
    	fout.open("file.txt");                  // I have no clue how to have the user pick the file name
    	fout << "your variable: " <<  variable << endl;				// this couts(or fouts) wutever is in the variable calle "varibakle" into file.txt
    	fout.close();
        system("pause");
    return 0;
    }

  2. #2
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330
    Just what is in this "ultimate.h" file?

  3. #3
    Seven years? civix's Avatar
    Join Date
    Jul 2002
    Posts
    605
    it contains include commands for common included files such as iostream.h and stdlib.h . I use it as a shortcut.

  4. #4
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330
    That's bad practice. Just put the includes in the source file you're using them directly in. To use the string library:

    Code:
    #include <string>
    
    using namespace std;

  5. #5
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    he doesnt really care (i know him on aim) its not like matters it gives you less to look @t
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  6. #6
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330
    If he wants to practice inefficient programming methods, that's up to 'im

  7. #7
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    ok.. wutever
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  8. #8
    Rebooted Inquirer's Avatar
    Join Date
    Apr 2002
    Posts
    281

    What exactly does it output?

    Does it only output the first letter? that may be because variable is only a char. and why did you make it a global string? Maybe i am still too much of a n00b, but, that doesn't look right to me.
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  9. #9
    Seven years? civix's Avatar
    Join Date
    Jul 2002
    Posts
    605
    well, it outputs one word and leaves out the first letter. I'm about to give up on this one, lol.

  10. #10
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    try making the 'variable' variable an array of chars. I'd try compiling your code, but I dont know whats in "Ultimate.h"...
    Please direct all complaints regarding this post to the nearest brick wall Have a nice day.

  11. #11
    Refugee face_master's Avatar
    Join Date
    Aug 2001
    Posts
    2,052
    And God Dammit Civx! Fix your avatar!
    Please direct all complaints regarding this post to the nearest brick wall Have a nice day.

  12. #12
    Seven years? civix's Avatar
    Join Date
    Jul 2002
    Posts
    605
    Heres the code with ultimate.h translated.

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    #include <windows.h>
    #include <conio.h>
    #include <time.h>
    #include <stdarg.h>
    #include <iostream>
    #include <cstdlib>
    #include <fstream>
    #include <fstream.h>
    #include <io.h>
    #include <fstream.h>
    #include <string.h>
    #include <dos.h>
    #include <string>
    
     using namespace std;
     
    char main()
    {
    startwrite:HANDLE hStdout;
    hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
        SetConsoleTextAttribute(hStdout, BACKGROUND_BLUE);
        cout<<"                       ---[The Civic Wordedit]---                           _ X"<<endl;
        textcolor(LIGHTGRAY);
    
        cin.get();
    	ofstream fout;
        char variable[0];
        cin>>variable;
                                     
    	fout.open("file.txt");
        fout<<variable;
        fout.close();
        cin.get();
         
    return 0;
    }
    And im making a new avatar in flash

  13. #13
    Registered User
    Join Date
    Jun 2002
    Posts
    267
    Originally posted by face_master
    And God Dammit Civx! Fix your avatar!
    Ever consider that the little red X is his avatar? Hmmmm???

  14. #14
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330
    Urh... you're not using even a 1/4 of the stuff you're including. Talk about unnessecary compile time...

    Also, int main () is the standard, just pointing that out...

    An array of 0 elements isn't a good idea either

  15. #15
    Seven years? civix's Avatar
    Join Date
    Jul 2002
    Posts
    605
    Yeh i copied that directly from my complier. I had been playing around with various lines...

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. help with text input
    By Alphawaves in forum C Programming
    Replies: 8
    Last Post: 04-08-2007, 04:54 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Function is called and I am trying to open a file
    By tommy69 in forum C Programming
    Replies: 88
    Last Post: 05-06-2004, 08:33 AM

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