• Create Account

## fstream

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

2 replies to this topic

### #12COOL4-U  Members

122
Like
Likes
Like

Posted 20 October 2001 - 04:37 AM

For my project I''ve written data to a file, only containing numbers from 0 to 5 seperated by a space and I want to read all numbers in it and put it in an array. The text file contains 150 lines each with 150 numbers with a space between two numbers. Like this: 0 0 0 1 1 1 0 0 0 1 1 1 0 0 0 1 1 1 I want to read it and put it back into an integer array. Does someone know how, thanks. Jeroen "2COOL4-U" de Haas - DefenceAlliance Project Leader/Coder - TacticalOps Linux Beta Tester

### #2Bezzant  Members

122
Like
Likes
Like

Posted 20 October 2001 - 04:59 AM

this should work, its probably not the best method but should be ok to use...

  void ReadData(char ReadDataFilename[20]){ std::ifstream DATA(ReadDataFilename); if(DATA) {for(int i=0; i> Num[i]; } }else { cout<<"could not load data..."<

then in your main function call ReadData("filename.dat") (or whatever you called it)

if this is not the best way for the task, please tell me, as i use it often.

thanks

EDIT: if you want to put the data back into a 2d array: Num[x][y] (or whatever) just add another 'for' loop and so then you have:
  for(int i=0; i> Num[i][o]; }} `

that should work, probably wont... ho hum!

Edited by - Bezzant on October 20, 2001 12:08:57 PM

### #32COOL4-U  Members

122
Like
Likes
Like

Posted 20 October 2001 - 09:02 PM

It works! thx I am using it for a map system for my RTS: http://2cool.free.fr/rts.html

Jeroen "2COOL4-U" de Haas