Yagami
Yagami

Reputation: 339

Saving An Array of Number into A Spesific File and Call It Later

Is there any command in C++ that I can use as reference to save an array of numbers into a spesific file that I can access and call it as an array of numbers as well in the next day? I am working on a ton of numbers, the thing is I know how to input those numbers into array, but I just dont want to input all of them again and again everytime I access the program, so is there any chance to input them at one time only? what I find out there is to save the file into .txt file, which is if I call it later it will be a "text" data, and i cant use that numbers on my project.

Upvotes: 0

Views: 81

Answers (2)

Heath Raftery
Heath Raftery

Reputation: 4159

Your terminology is non-standard, so I suspect you're having trouble understanding how to find answers.

C++ doesn't have "commands". The closest two things you might mean are keywords and functions. Keywords are integral to the language, but do very low level things, like break, return, for and while. Functions are collections of C++ statements that you can call as one unit. There are various libraries that contain related sets of functions. The most common library in C++ is the C++ standard library, which contains functions like std::fopen and std::puts which are useful when writing to files.

In addition to the library functions, there are functions you can write yourself. The advantage of those is that you can easily study and modify the contents of the function to achieve just what you want.

Since you use the term "reference", I gather you're looking for a function that you can read to modify for your own purposes.

In that case, check out this collection of code. You could make some modifications and wrap it in a function to do what you want. In particular, note the for loop with the out_file<< num_array[count]<<" "; statement for how to write to a file, and the second for loop with the in_file >> a; statement for how to read the file back.

Upvotes: 1

Related Questions