0

It might sound stupid to most of you.....but it is the first time i want to write 2 columns of data in a txt file.....The first column will be an index of the second column. The second column has constant length but the index will have length from 1 to 4 digits(1-5000) and i would like to know what should i do or use in order to have a constant size for the first column(say 4 digits).I would like to have 2 "tidy" columns

say i have

ofstream file;
file.open("text.txt");
............
code
............
file<<index<<data[index]<<endl;

file.close();

where index is a loop counter and data is an array.

Thanks in advance mates

3
Contributors
3
Replies
4
Views
9 Years
Discussion Span
Last Post by zourlas
1
#include <iomanip>
#include <iostream>
using namespace std;

int main()
  {
  for (int n = 1; n < 6; n++)
    cout << n;
  cout << setw( 5 ) << right << (167) << "mm\n";
  return 0;
  }

Hope this helps.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.