Go Down

Topic: Read from file (Read 1 time) previous topic - next topic

Dust

Hello,

Could someone tell me how to read from a text file in C++ in the Arduino sketchbook...I seem to be missing something.

Thanks!

simond

Do you mean read from a text file in your sketch? I'm curious as to the location of this file for it to be accessible by the running app on the arduino. In general, though, the C functions read(), open(), and friends such as fopen() will be helpful, and in C++ the iostream operators such as cin.


Dust

I'm trying to pull some info from a text file so that I can use the information.  My C++ is a bit rusty but I'm trying something like :

Code: [Select]
#include <ifstream>
#include <cstdlib>
using std::ifstream;
using std::cout;


void setup()
{
 ifstream inStream;
 String temp;
 inStream.open("test.txt");
 inStream >> str1;
 cout << str1;
 inStream.close();


Just to see if I can get something from it, but it's giving me the error:
ifstream: No such file or directory.

Is there a better way to approach this?

MysteriousAges

I can't remember exactly, but I thought the file objects were in the header file "fstream".

Dust

I get the same thing when I try fstream as well.

mellis

The Arduino board doesn't have a filesystem, so there aren't any files to read from.  If you want to write a program that runs on the computer, reads files, and communicates with the sketch running on the Arduino board, you'll need to use some other development platform (e.g. a standard C++ compiler).

Go Up