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,675
    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
    }
    I used to be an adventurer like you... then I took an arrow to the knee.

  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