Pages: [1]   Go Down
Author Topic: Read from file  (Read 998 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Atlanta, GA
Offline Offline
Jr. Member
**
Karma: 0
Posts: 51
Arduino boulders
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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?
Logged

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 64
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

0
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 9
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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).
Logged

Pages: [1]   Go Up
Jump to: