I put all the contents of an array a[16] into a file. But when i read them how can i separate those numbers from each other instead of adding a space.

what about putting the contents into a new line like
0 14
1 24

How do i do that and read it,is there any easier solution ? i am just a beginner,so keep it simple.

A newline is a whitespace. Your ifstream object's read location should see it and automatically move to the next line and read the next value. Just be sure you don't add the line numbers like you appear to be showing, they will be read as additional input. Unless you somehow plan for them in your code, you would wind up with 32 inputs instead of the anticipated 16.

the reading part isnt so easy. id recomend typing into google reading from file. or look at a File I/O.

for storing its pretty easy.

if you start with an empty project(in Dev C++ or microsoft VC++). and put a "filename".cpp file in the source folder of you program and code from there including the header files <iostream> and <fstream>. Then all you have to do is store the user input by putting it into an array then putting the array into the textfile.

this shows you how to put the file with extra stuff.

DefinedFileName << yourarray << "\n"

you can put what ever you want into those qouts. like even " " meaning space. and even adding somthing else if you want. just by putting "<<".

this should help you with that. i strongly suggest you look up File I/O C++. that will show you how to hold data when opening files or deleting all the data in a file etc.

or click below and look at a tut that i used when i was learning it.


from there its just trying it out and see what it does and what you can make it do.

Good luck,

P.S. if you need help in other areas you dont understand that i just assumed you would. like getting a line from the user and putting it into and array. please let me know and i can go more into detail