user11827: I wrote some code in C++ (Used libraries like fstream, vectors etc.) Now when I transferred the code to Arduino it wouldn't compile so I added the following library: https://github.com/maniacbug/StandardCplusplus I downloaded the IDE from here: https://www.arduino.cc/en/main/software
Now almost all my code works: All the libraries I've used work except for fstream which I've used to read a specific file.
Now is there a certain problem with the 'StandardCplusplus' library and how can I counter this problem.
Plus can someone give me an alternative for fstream that works with Arduino. Was reading a bmp image using C++. Now fstream works in a certain way (reads the file in a certain way). Is there some alternative to fstream.

user10794: The Arduino IDE does compile your code using the avr-g++ compiler. In other words, it is C++.

Was reading a bmp image using C++. 

This isn't practical on the smaller Arduinos, at least, because they have so little RAM. They also don't have a file system. There is a streaming library for output, which is very handy for streaming out things to Serial, LCDs, etc.
One of the replies here mentioned that if you switch to Atmel Studio you can look at the datasheet and get down to the intricacies of the hardware. Well, you can certainly do that as well with the IDE. All the hardware registers are available for use. I often use the "bare" registers for timers, watchdog, interrupts etc.
Also Atmel Studio only runs on Windows. You are out of luck if you use a Mac or Linux.
There is also a port of the Standard Template Library for the Arduino, if you want to use vectors, lists, maps etc. 
There is also another port of the STL which may work better and be easier to install.

user11742: Are you using Arduino UNO? Look at the datasheet and see how much RAM the Arduino has. Assuming you are using Arduino Uno, it should be around 2kilobyte or less. So it is highly likely not to have enough memory to read the BMP file. Even if you are trying to read very small BMP file, the code reading the file would vary depending where you are reading the BMP file from (SD Card, SPI Flash memory, etc.) It cannot read files directly from your computer using just fstream. 

user-1: If you want to write C++ for an Arduino, I'd recommend you cease using the Arduino IDE and instead use Atmel Studio. The microcontroller on board is an Atmel AVR, and you can write for that using the gcc-avr toolchain that comes with Atmel studio.
You'll lose the spiffy libraries that come with the arduino platform that abstract away a lot of the intricacies of the hardware, and you'll instead be looking at the AVR datasheet and the schematic of the arduino, but you'll learn quite a bit in the process and have direct control over the hardware.
With all that said though, the AVR does not have a file system so using fstream doesn't make any sense to begin with.

user43104: When you run that library on the Arduino and ask it to open a file, where do you imagine it would read the file from? Your Arduino has no hard disk or other file system.
One way to solve this is to include a library that emulates a read-only file system in the Arduino's flash. I dunno whether this exists (such libs do exist for for some other targets, for instance for the Nintendo DS), but it would be a bit of overkill IMO.
Another way is to include the data that is in the file in your program, as a const (expr) array of bytes, and read from that array instead of from the file. But if you have a library that is coded to use file read calls this would require some rewriting.
A third approach would be to do the reading and interpreting of the file on your host PC, output the interpreted content to a const (expr) byte array, and include that in your application. This frees you from having to include the bmp-read code in your image.

11827: <p>I wrote some code in C++ (Used libraries like fstream, vectors etc.) Now when I transferred the code to Arduino it wouldn't compile so I added the following library: <a href="https://github.com/maniacbug/StandardCplusplus" rel="nofollow">https://github.com/maniacbug/StandardCplusplus</a> I downloaded the IDE from here: <a href="https://www.arduino.cc/en/main/software" rel="nofollow">https://www.arduino.cc/en/main/software</a></p>

<p>Now almost all my code works: All the libraries I've used work except for fstream which I've used to read a specific file.</p>

<p>Now is there a certain problem with the 'StandardCplusplus' library and how can I counter this problem.</p>

<p>Plus can someone give me an alternative for fstream that works with Arduino. Was reading a bmp image using C++. Now fstream works in a certain way (reads the file in a certain way). Is there some alternative to fstream.</p>
 10794: <p>The Arduino IDE <em>does</em> compile your code using the avr-g++ compiler. In other words, it <em>is</em> C++.</p>

<blockquote>
  <p>Was reading a bmp image using C++. </p>
</blockquote>

<p>This isn't practical on the smaller Arduinos, at least, because they have so little RAM. They also don't have a file system. There is a <a href="http://arduiniana.org/libraries/streaming/" rel="nofollow">streaming</a> library for output, which is very handy for streaming out things to Serial, LCDs, etc.</p>

<p>One of the replies here mentioned that if you switch to Atmel Studio you can look at the datasheet and get down to the intricacies of the hardware. Well, you can certainly do that as well with the IDE. All the hardware registers are available for use. I often use the "bare" registers for timers, watchdog, interrupts etc.</p>

<p>Also Atmel Studio only runs on Windows. You are out of luck if you use a Mac or Linux.</p>

<p>There is also a port of the <a href="http://andybrown.me.uk/wk/2011/01/15/the-standard-template-library-stl-for-avr-with-c-streams/" rel="nofollow">Standard Template Library</a> for the Arduino, if you want to use vectors, lists, maps etc. </p>

<p>There is also <a href="https://github.com/maniacbug/StandardCplusplus" rel="nofollow">another port of the STL</a> which may work better and be easier to install.</p>
 11742: <p>Are you using Arduino UNO? Look at the datasheet and see how much RAM the Arduino has. Assuming you are using Arduino Uno, it should be around 2kilobyte or less. So it is highly likely not to have enough memory to read the BMP file. Even if you are trying to read very small BMP file, the code reading the file would vary depending where you are reading the BMP file from (SD Card, SPI Flash memory, etc.) It cannot read files directly from your computer using just fstream. </p>
 -1: <p>If you want to write C++ for an Arduino, I'd recommend you cease using the Arduino IDE and instead use Atmel Studio. The microcontroller on board is an Atmel AVR, and you can write for that using the gcc-avr toolchain that comes with Atmel studio.</p>

<p>You'll lose the spiffy libraries that come with the arduino platform that abstract away a lot of the intricacies of the hardware, and you'll instead be looking at the AVR datasheet and the schematic of the arduino, but you'll learn quite a bit in the process and have direct control over the hardware.</p>

<p>With all that said though, the AVR does not have a file system so using fstream doesn't make any sense to begin with.</p>
 43104: <p>When you run that library on the Arduino and ask it to open a file, where do you imagine it would read the file from? Your Arduino has no hard disk or other file system.</p>

<p>One way to solve this is to include a library that emulates a read-only file system in the Arduino's flash. I dunno whether this exists (such libs do exist for for some other targets, for instance for the Nintendo DS), but it would be a bit of overkill IMO.</p>

<p>Another way is to include the data that is in the file in your program, as a const (expr) array of bytes, and read from that array instead of from the file. But if you have a library that is coded to use file read calls this would require some rewriting.</p>

<p>A third approach would be to do the reading and interpreting of the file on your host PC, output the <em>interpreted</em> content to a const (expr) byte array, and include that in your application. This frees you from having to include the bmp-read code in your image.</p>
