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

  • Home
  • SEARCH
  • 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 8728829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:43:21+00:00 2026-06-13T08:43:21+00:00

I wish to output data from my program to a text file. Here is

  • 0

I wish to output data from my program to a text file. Here is a working example showing how I do it currently, where I also include the date/time (I am running Windows):

#include <iostream>
#include <fstream>
#include <time.h>

using namespace std;

int main()
{

char dateStr [9];
char timeStr [9];

_strdate(dateStr);
_strtime(timeStr);

ofstream output("info.txt", ios::out);
output << "Start time part 1 " << "\t" << timeStr << " on " << dateStr << "\n";
output << "Start time part 1000000 " << "\t" << timeStr << " on " << dateStr << "\n";
output.close();


return 0;
}

However the output of “info.txt” is not very readable to me as a user, since the time- and date stamp at the ends are not aligned. Here is the output:

Start time part 1   15:55:43 on 10/23/12
Start time part 1000000     15:55:43 on 10/23/12

My question is, is there a way to align the latter part?

  • 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-06-13T08:43:22+00:00Added an answer on June 13, 2026 at 8:43 am

    Yes, <iomanip> header provides the setw manipulator, letting you set the width of each field that you output to an ostream. Using setw manipulator for each row instead of tab characters would provide tighter control over the output:

    output << setw(25) << "Start time part 1 " << timeStr << " on " << dateStr << endl;
    output << setw(25) << "Start time part 1000000 " << timeStr << " on " << dateStr << endl;
    

    To align strings on the left, add left manipulator:

    output << left << setw(25) << "Start time part 1 " << timeStr << " on " << dateStr << endl;
    output << left << setw(25) << "Start time part 1000000 " << timeStr << " on " << dateStr << endl;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wish fetch data in a XML file, where Tag is a variable.. My
I have a set of classes I wish to serialize the data from. There
I wish to serialize from C sharp to JSON. I would like the output
I have 5 tables that I wish to get data from all linking to
I am having this rather long json output in my controller, I wish to
I wish to make the uploaded file contents only viewable on the browser i.e
First some background. I'm parsing a simple file format, and wish to re-use the
DATA AND REQUIREMENTS The first table ( myMatrix1 ) is from an old geological
I'm running a bat file and having the output displayed in the console window.
In ASP.NET I wish to empty/clear/reset the contents on an Image data type in

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.