New lines

This is a discussion on New lines within the C++ Programming forums, part of the General Programming Boards category; I want to output a new line into a text file but i dont know how please help Ex: jaime ...

  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,801
    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
    #include<xErath.h> xErath's Avatar
    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-20-2008, 11:58 PM
  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, 04:45 AM
  5. count only lines of code...
    By flightsimdude in forum C Programming
    Replies: 13
    Last Post: 09-23-2003, 07:08 PM

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