Menu

Main Menu
Talk Get Daily Search

Member's Online

    User Name
    Password

    [solved](.cpp)"Hello world" in n900 (getting error) plz guide me.

    Reply
    Page 2 of 4 | Prev |   1   2   3     4   | Next
    slvr32 | # 11 | 2011-06-15, 17:08 | Report

    Originally Posted by SubCore View Post
    you need to tell g++ where to look for conio.h, usually via the -L switch.
    I think you mean '-I' for including header files in non-standard paths, whereas -L is a linker flag for libraries.

    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.

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by slvr32; 2011-06-15 at 17:17.
    The Following User Says Thank You to slvr32 For This Useful Post:
    SubCore

     
    nicholes | # 12 | 2011-06-15, 17:09 | Report

    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!

    Edit | Forward | Quote | Quick Reply | Thanks
    Attached Images
     

    Last edited by nicholes; 2011-06-15 at 17:13.

     
    slvr32 | # 13 | 2011-06-15, 17:11 | Report

    Originally Posted by nicholes View Post
    can you give an example here for me how to get rid of conio.h and getch()?

    Code:
    # include <stdio.h>
    
    int main (void)
    {
    printf ("hellow wolrd");
    getchar();
    
    }
    compiles with...

    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

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by slvr32; 2011-06-15 at 17:18.
    The Following 2 Users Say Thank You to slvr32 For This Useful Post:
    nicholes, uppercase

     
    nicholes | # 14 | 2011-06-15, 17:27 | Report

    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

    Edit | Forward | Quote | Quick Reply | Thanks

     
    SubCore | # 15 | 2011-06-16, 08:43 | Report

    Originally Posted by nicholes View Post
    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
    after it compiles without error, you have to make the resulting file (a.out is default) executable by "chmod +x a.out". this has to be done in a folder which supports this flag, MyDocs is a FAT filesystem which does NOT support it.
    copy it to /home/user f.ex., then use chmod +x.

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 3 Users Say Thank You to SubCore For This Useful Post:
    nicholes, nicolai, uppercase

     
    Captwheeto | # 16 | 2011-06-16, 09:24 | Report

    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>
    using namespace std;
    
    main() {
    	cout << "hello, world\n";
    	if (cin.get() == '\n')
    	return 0;	
    }

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by Captwheeto; 2011-06-16 at 09:30.
    The Following 3 Users Say Thank You to Captwheeto For This Useful Post:
    demolition, nicholes, onethreealpha

     
    onethreealpha | # 17 | 2011-06-16, 10:48 | Report

    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++"

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 3 Users Say Thank You to onethreealpha For This Useful Post:
    Captwheeto, demolition, nicholes

     
    demolition | # 18 | 2011-06-16, 11:45 | Report

    @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
    • main() ends with return 0 but doesn't define a return type, thus won't compile.
    • It's better style (safer) to put the using inside the scope it's being used; in this case move it inside main() or drop it altogether and use std:: because the programme's so short.
    • There's no need to add \n at the end of each string. Using " at the beginning and end of a string turns it into a std::string.

    re: onethreealpha' code
    • The programme will run but might do so without the user being able to see the output. It is advisable to put something before main returns such as char anyLetter; std::cin>>anyLetter; Or system("PAUSE") if the compiler supports it.

    Code:
    #include <iostream>		// use correct i.e. C++ library
    
    int main()			// declare return type
    {
    	using namespace std;	// do this inside scope
    
    	cout << "hello, world";	// self-terminating string
    
    	system("PAUSE");	// requires user input (keypress) to quit
    
    	return 0;		// return an int
    }
    Look at this book, it really helped me:
    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.

    Edit | Forward | Quote | Quick Reply | Thanks

    Last edited by demolition; 2011-06-16 at 13:17. Reason: typo!
    The Following 2 Users Say Thank You to demolition For This Useful Post:
    Captwheeto, nicholes

     
    SubCore | # 19 | 2011-06-16, 11:54 | Report

    Originally Posted by demolition View Post
    Or system("PAUSE") if the compiler supports it.
    system() is evil. case in point: "pause" is a windows/dos command, and won't work here.

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following 2 Users Say Thank You to SubCore For This Useful Post:
    demolition, nicholes

     
    momcilo | # 20 | 2011-06-16, 12:04 | Report

    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.

    Edit | Forward | Quote | Quick Reply | Thanks
    The Following User Says Thank You to momcilo For This Useful Post:
    demolition

     
    Page 2 of 4 | Prev |   1   2   3     4   | Next
vBulletin® Version 3.8.8
Normal Logout