![]() |
[solved](.cpp)"Hello world" in n900 (getting error) plz guide me.
1 Attachment(s)
Here i have done a few things on my N900 from
http://ossguy.com/?p=475 to run .cpp files and when i try to run this using g++ it shows error here is my programme # include <stdio.h> # include <conio.h> int main (void) { printf ("hlloe wolrd"); getch(); } UPDATE: Thanks to all of you guys i managed to run and also modify .cpp files now (i am using filebox along with the leafpad to edit .cpp) |
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
I've never touched C++ but I have done a little C.
Is there any reason why you're using them headers? You should only need stdio, like so #include <stdio.h> int main(void) { printf("hello, world\n"); return 0; } unless you were planning to expand. Were you trying to get stdin from the user? I'm Perl/Haskell guy. Sorry I can't be of more help |
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
Quote:
|
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
Quote:
also i am using <conio.h> header file to use getch() for "heelo wolrd" to remain on the screen |
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
Quote:
i wont to show them all THE POWER OF N900! |
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
you need to tell g++ where to look for conio.h, usually via the -L switch.
but google tells me that conio.h is a very old msdos library, i doubt it'll work in this environment. try something like "cin.get()" (and #include <iostream>) |
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
Quote:
|
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
Quote:
|
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
Quote:
|
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
Quote:
|
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
Quote:
But I agree with conio.h and getc() being old ms-dos legacy. What about getchar()? Also only needs stdio.h, but I'm not sure about the buffered/unbuffered input issue. |
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
1 Attachment(s)
i got this
#include <stdio.h> main() { for( ;; ) { printf ("Hello World!\n"); } } but this is for loop and works on pc and when i try to run this on n900 like in my first post.. this time nothing happened and put me back to Mydocs it shows nothing! |
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
Quote:
Code:
# include <stdio.h> g++ hello.cpp and runs with... ./a.out where a.out is the default name for executables created with gcc/g++, if you don't specifiy a different output file with -o, e.g. g++ -o myprogram hello.cpp |
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
there is no error now but it does not execute also(i think problem is related to device now not in programme)
BTW thanks to all you guys for so quick reply |
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
Quote:
copy it to /home/user f.ex., then use chmod +x. |
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
It looks like you're writing just plain C anyway.
I've just written my first ever bit of C++ code so don't laugh ;) Code:
#include <iostream> |
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
for c++ try this
#include <iostream> using namespace std; int main() { cout << "Hello world!" << endl; return 0; } this will give you the "hello world" with confirmation of correct operation and ask for keyboard input to finish (return 0 to main) iostream is required for input/output functions printf is the "C" equivalent cout when using "C++" |
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
@nicholes
Just to reiterate: your initial code is mostly C, not C++. To write C++, use the correct libraries (iostream in this case) and C++ functions e.g. std::cout in place of printf. I might do things slightly differntly to the above two suggestions... re: Captwheeto's code
re: onethreealpha' code
Code:
#include <iostream> // use correct i.e. C++ library http://www.acceleratedcpp.com/ You might think it's a bit old but it's really good for the basics, especially using the standard template library. |
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
Quote:
|
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
I assume you are trying DOS/WIndows based c++ example.
Please note that getch does not exist in gnu linux. As someone pointed out, you need to use getchar, but prior to that you have to modify the terminal settings (from within code). The functioning of getchar depends on terminal settings in order to emulate getch. By default it returns no matter what/if the key was pressed. See the manual termios.h and tcgetattr. |
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
Quote:
These will work. Simple way (but might not be visible) Code:
#include <iostream> // use correct i.e. C++ library Code:
#include <iostream> // use correct i.e. C++ library |
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
1 Attachment(s)
Quote:
since i am very very new in coding so i want to know what to type in xterminal after this (see image) i have got a.out in home/ user/ (see my first post to know what i have installed on n900 to run .cpp) (i myself not clear what i have done! lol) |
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
Quote:
Code:
chmod +x a.out Code:
./a.out |
Re: (.cpp)"Hello world" in n900 (getting error) plz guide me.
Quote:
hello world apeared thanks to all CHEERS!!!!!!!!:) |
Re: [solved](.cpp)"Hello world" in n900 (getting error) plz guide me.
Not being a real C or C++ programmer, should the logic of the program not be something like:
While no user input -> Hello World. :confused: |
Re: [solved](.cpp)"Hello world" in n900 (getting error) plz guide me.
Quote:
The entry point of a C++ programme is main(), or pseudo-name thereof. The first command in main(), for this programme, is to stream a string to the standard output (console). The next is to return i.e. to end. In more complex programmes one might want {while(no user input){action}}, but here it's really simple. The other reason for saying No is in C++ while is a loop, so your logic would produce many, many "hello, world" s. However, only one is required. |
Re: [solved](.cpp)"Hello world" in n900 (getting error) plz guide me.
Quote:
I do agree that the linear programming does the job probably with the smallest effort and tightest code. |
Re: [solved](.cpp)"Hello world" in n900 (getting error) plz guide me.
1 Attachment(s)
One more qustion
#include <iostream> int main() { int s; //salry printf("enter your salary"); scanf ("%d",&s); if (s>=1000) { if (s>=3000) { if (s>=5000) printf ("your bonus is 500"); else printf("your bonus is300"); } else printf("your bonus is100"); } else printf("no bonus"); system("PAUSE"); } it execute and works perfact but sh:pause not found comes!! Any way to get rid of it |
Re: [solved](.cpp)"Hello world" in n900 (getting error) plz guide me.
Now, you really need to stop using C standard functions, like printf and scanf. The C++ equivalents make the code easier to read and are *just as well implemented* in the STL (standard template library). C code will normally compile because C++ is a superset of C and some software, e.g. win32, hasn't been fully converted to C++ yet.
Next, as mentioned above, system("pause") doesn't work outside dos/windows. If your programme just runs and exits without you being able to see the output try my v2. It seems you are very new to programming overall - no worries and well done for giving it a go. Amongst other paradigms, Encapsulation and Abstraction are part of the bedrock of C++, as an OO language. In programming, encapsulation means wrapping functionality together. And, abstraction means removing or separating one bit of functionality from another. I will edit this post in a minute with the C++ version of your code. ps - any chance you can either start a new thread or remove the Solved if you've got more questions. Bit misleading otherwise. |
Re: [solved](.cpp)"Hello world" in n900 (getting error) plz guide me.
Yeah I said this earlier. You're writing just plain C in a very procedural manner, I think you need to look for a better C++ resource, one that is aimed at linux or uses standard headers, operators and such.
You could learn C if you like, I would recommend it over C++, but if you're looking for a career in programming then stick with OO languages like Python, C++ or Java |
Re: [solved](.cpp)"Hello world" in n900 (getting error) plz guide me.
Good beginners website HERE if you're interested in C++
i found it great when I started learning C++ |
Re: [solved](.cpp)"Hello world" in n900 (getting error) plz guide me.
Quote:
also my problem is solved by execute the .cpp so i changed the thread title by "[solved]" and for small questions i don't want to start a new thread and become a part of spam!!(no offence plz) again Thanks to all of you! |
Re: [solved](.cpp)"Hello world" in n900 (getting error) plz guide me.
Quote:
Code:
#include <iostream.h> edit: just saw your post about being taught C so you can disregard my comment about using c++ functions :) |
Re: [solved](.cpp)"Hello world" in n900 (getting error) plz guide me.
Quote:
|
All times are GMT. The time now is 01:08. |
vBulletin® Version 3.8.8