Question:
Where do i write a C++ program on a Raspberry Pi? I mean, do i use the Terminal for this or the Idle?
Alex
2013-05-25 08:25:28 UTC
Where do i write a C++ program on a Raspberry Pi? I mean, do i use the Terminal for this or the Idle?
I need to write a C++ program to get get some readings of some sensors (i have a sensor shield) and i don't know where exactly to start writing it (or how to run/compile it, for that matter).
Three answers:
jplatt39
2013-05-25 08:50:52 UTC
First question, which OS are you using for Rasberry Pi? If Raspbian check this page:



http://raspberrypi.stackexchange.com/questions/4813/how-to-install-c-compiler-on-raspberry-pi



And in that case just use the terminal and any tutorials for using gcc or make which you can get your hands on. Seriously a simple compilation would be "g++ -o .cpp" replacing of course -- but if you don't use the -o and program name then what happens is you get an executable named a.out -- a real hassle.



but look up the compiler for the OS you are using.



EDIT: Just saw husoski's answer. I've been using Linux since it was mostly terminal-based and, if you are using a Linux OS then I want to recommend a text-based editor called nano. You run it in your terminal and it's a stand-alone replacement for pico which was distributed as part of the pine mail system. Simply put it's small, fast and has most of the commands on the screen. Also, if you are using Linux an easy way to create the text file he did -- or any other -- is to use 2 pipes as in:



cat > informal.cc << "EOF"

#include

using namespace std;

int main(){

cout <<"Hiya world! Howya doin'?" << endl;

return 0;

}

EOF



cat means copy or type -- the default is keyboard input. > means write to a file, and overwrite it if it exists << or >> mean in this case write to a file and append to it if it exists, and in this case <<"EOF" means write to the file until you enter EOF on a line by themselves. The other way to close a file you are writing that way is control-D but this is easier to remember.
?
2016-12-11 21:57:12 UTC
a million & 2. besides the fact which you exhibit on the console is their consistently. you will in no way be waiting to delete or edit any text textile, a minimum of no longer with any of the ANSI C/C++ libraries. All you should do is output text textile to the exhibit. 3. relies upon on what's indoors the loop. For an empty limitless loop, there is one actuality that is consistently carried out: the increment (i++). for(int i = 0; genuine; i++) you prefer some expertise of assembly language purely to make a no longer basic estimate. E.g an infinite loop in MIPS assembly upload $t0, $0, $0 # i is initialized to 0, $t0 = 0 Loop: // stuff addi $t0, $t0, a million # i ++ j Loop # circulate to Loop if i < 4 If the upload preparation takes 4 clock cycles and the bounce preparation takes 3 cycles, that's a complete of 7 cycles consistent with new launch. If my processor runs MIPS code natively, and runs at 3 GHZ, that is 3 x 10^9 cycles consistent with 2nd, then (3 x 10^9)/7 = a a million/2 1000 million iterations must be carried out. that is an the perfect option decrease. procedures do no longer run for a million 2nd each and each and each and each. they might get 50 ms to run earlier being switched out of the processor. in case you prefer a real time estimate, purely time it utilising the languages' libraries. 4. you prefer to prepare a Widget toolkit (a.ok.a %./UI library) for GUI progression. See wxWidgets, living abode abode windows MFC, GTK+, QT for C/C++, and Swing for Java. 5. comparable subject, you prefer a %. library. %. progression interior of reason a step up from console progression, you would be wanting a surprising base in programming foundations first. a minimum of, there is a few trouble-free arithmetic involved approximately exceptionally lots all animations.
husoski
2013-05-25 09:12:17 UTC
Use the terminal, or get an IDE that supports C/C++ programming. Idle is for Python programming.



From the terminal, this on Scientific Linux:

[Husoski@localhost ~]$ which g++

/usr/bin/g++

[Husoski@localhost ~]$ mkdir cppstuff

mkdir: cannot create directory `cppstuff': File exists

[Husoski@localhost ~]$ cd cppstuff

[Husoski@localhost cppstuff]$ cat >hello.cpp

#include

using namespace std;

int main()

{

cout << "hello, raspberry!" << endl;

return 0;

}

[Husoski@localhost cppstuff]$ g++ -o hello hello.cpp

[Husoski@localhost cppstuff]$ ./hello

hello, raspberry!



That's about the dumbest way to enter a program, but it works. Use any text editor. I tend to use gedit on Linux. (I find the traditional emacs and vi/vim programming editors too arcane for my tastes, but you might find them useful. In particular, emacs has a very powerful macro facility.)



For graphical development environment, see If you can get Code::Blocks installed on your system, it's particularly nice for C/C++. Eclipse is good too.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...