Reading & Writing data in text file

Hey Guys. I need your help. Can someone please tell me the code to write data(Double type e.g 12345.67891) in text file like pattern given below. Remember to put tab between each column.
-----------------------------------------------------
Column1 Column2 Column3
Value 1 Value 2 Value 3
Value 4 Value 5 Value 6
Value 7 Value 8 Value 9
-----------------------------------------------------
& Also how to read data from this file.
Sorry for bad english writing.
Last edited on
closed account (jh5jz8AR)
Hey AdnanAhmed008

You can use the header file fstream

It is actually pretty neat as I am learning more about it myself.

for example:

1
2
3
4
5
6
7
ifstream inFile;

inFile.open ("textFile.txt")

inFile >> value1;

cout << value1;


This should get you going. If you are still having an issue, post your code and I will be glad to take a look at it.
Main problem is that how i format text in file. I mean space between column & its values.
you can easily write to an ofstream like this:
1
2
double d = 5.5;
os << d;

To insert tabs, just use the escape character '\t':
 
cout << "TA\t" << 'B' << '\n';


As already has been said, show some code, where your problem exists.
Maybe what your "text format" currently looks like and what you want it to look like
Topic archived. No new replies allowed.