writing a string to .txt

This is a discussion on writing a string to .txt within the C++ Programming forums, part of the General Programming Boards category; how can jou like in the folder \logs from the program like var="name".txt var="antwoord.txt...

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    56

    writing a string to .txt

    how can jou like in the folder \logs
    from the program like

    var="name".txt var="antwoord.txt
    if x == y , y == x

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,691
    Get a good book on C++ programming.
    Or read the Tutorial.

    gg

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Using file streams:
    Code:
    ofstream WriteFile;
    WriteFile.open("MyFile.txt", ios::out);
    if(!WriteFile.fail())
    {
       WriteFile << "Hello notepad!" << endl;
       WriteFile.close();
    }
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Registered User
    Join Date
    Jan 2003
    Posts
    56
    but how to do it to a file thst the user write's

  5. #5
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    u would write n create the file in notepad then:

    Code:
    ifstream infile;
    char ch;
    
    infile.open("somefile.txt");
    
    infile.get(ch);
    
    while (! infile.fail())
    {
       cout << ch << endl;
       infile.get(ch)
    }
    that what you mean?

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by gamer
    but how to do it to a file thst the user write's
    To let the user decide which file? (actually, I'm having a little trouble understanding what you mean).
    Use cin so the user can enter a filename:
    Code:
    char FileName[64];
    
    cout << "Enter a filename: ";
    cin >> FileName;
    
    WriteFile.open(FileName, ios::out | ios::trunc);
    
    etc...
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  7. #7
    Registered User
    Join Date
    Jan 2003
    Posts
    56
    thank's

    it's that my mom is a teacher
    and the don't have software
    for math and stuff
    zo if you ask there name and write a file to
    it the teacher can look at it
    zo iam on my way to make a program as this
    if x == y , y == x

  8. #8
    Registered User
    Join Date
    Aug 2002
    Posts
    87
    I have a fairly good understanding of c++ and i speak dutch, as it seems you have problems with englich feel free to e-mail me with future questions at dirkhens@hotmail.com =]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 01:56 PM
  2. problems with overloaded '+' again
    By Brain Cell in forum C++ Programming
    Replies: 9
    Last Post: 04-14-2005, 06:13 PM
  3. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM
  4. creating class, and linking files
    By JCK in forum C++ Programming
    Replies: 12
    Last Post: 12-08-2002, 02:45 PM
  5. "Operator must be a member function..." (Error)
    By Magos in forum C++ Programming
    Replies: 16
    Last Post: 10-28-2002, 02:54 PM

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