Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4107806
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:33:53+00:00 2026-05-20T21:33:53+00:00

Can any body help me with this simple thing in file handling? The following

  • 0

Can any body help me with this simple thing in file handling?

The following is my code:

#include<iostream>
#include<fstream>
using namespace std;
int main()
{
  ofstream savefile("anish.txt");
  savefile<<"hi this is first program i writer" <<"\n this is an experiment";
  savefile.close();
  return 0 ;
}

It is running successfully now, I want to format the output of the text file according to my way.

I have:

hi this is first program i writer this is an experiment

How can I make my output file look like the following:

hi this is first program 
I writer this is an experiment 

What should I do to format the output in that way?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T21:33:53+00:00Added an answer on May 20, 2026 at 9:33 pm

    First, you need to open the stream to write to a file:

    ofstream file; // out file stream
    file.open("anish.txt");
    

    After that, you can write to the file using the << operator:

    file << "hi this is first program i writer";
    

    Also, use std::endl instead of \n:

    file << "hi this is first program i writer" << endl << "this is an experiment";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anybody help me with this simple code?? #include <iostream> using namespace std; void
can any body help me on separating this example of data that i need
Following is my code can Any body please tell me why it is not
Can anybody help with this code I just don't know where I am going
Can any body help me out how to clear the items in the list
I need your help if any one can be, it will be great thing
can anybody help me solve this : i got $filename= index 198.php; i use
Can anybody help me get this date format like Fri, 01 Oct 22:26:23 +0200
Can anybody please help me with this as I have no idea why public
can anybody help me understand how Honda achieved this effect: http://testdays.hondamoto.ch/ I mean the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.