Can I read data from an fstream inputFile?

0 votes
asked Feb 26, 2018 by SlinkEEE (120 points)
Beginner C++ question here!

I'd like to create a file called "numbers.txt" in onlinegdb, and then in my Main function I would like to open the file and read the data into an array of integers.

I'm not sure if this is possible, and if so, how could I get the file to open successfully? So far my program is running but it is telling me that the file could not be opened.

2 Answers

+3 votes
answered Feb 26, 2018 by anonymous
Yes. It possible.
Here is working example.
https://onlinegdb.com/Hyvi2l-_f
commented Jun 21, 2018 by Kristi Hansen (120 points)
Where does the file numbers.txt have to be located on my computer?
0 votes
answered Sep 1, 2019 by NavarroAndorid (300 points)
In order to read a file from a program you need to include it in the same project.  For example, you can have the data in data.txt and your code in myCode.  You can add additional files to your project using Ctrl + M.  When you list your projects, you will only be able to see the projects names but not the file they contain.  If you want to do so, you can download the project to your computer and unzip it.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...