Thread: New lines

  1. #1
    Registered User
    Join Date
    Oct 2004
    Posts
    12

    New lines

    I want to output a new line into a text file but i dont know how please help
    Ex:
    jaime adf
    new line

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Code:
    #include <fstream>
    #include <iostream>
    
    ...
    
    std::ofstream file("MyFile.Txt");
    if( file.is_open() )
    {
        file << std::endl;  // endl writes a newline character to the file
        file << '\n';   // This does the same thing
        file.put('\n'); // Also does the same thing
    }
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  3. #3
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    Print this string the way you want:
    Code:
    "jaime adf\nnew line"
    Note the '\n' char which represents a newline char.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 10-07-2008, 06:19 PM
  2. Print out first N lines
    By YoYayYo in forum C Programming
    Replies: 1
    Last Post: 02-21-2008, 12:58 AM
  3. Reading lines from a file
    By blackswan in forum C Programming
    Replies: 9
    Last Post: 04-26-2005, 04:29 PM
  4. Question About Reading Lines from stdin
    By Zildjian in forum C Programming
    Replies: 7
    Last Post: 11-12-2003, 05:45 AM
  5. count only lines of code...
    By flightsimdude in forum C Programming
    Replies: 13
    Last Post: 09-23-2003, 07:08 PM