ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
dmail, your code worked fine. I am studying it.
I have a couple of questions:
Why did you have
Code:
void print_question(int const& x,int const& y)
{
std::cout << "\nYour coordinates are: \n" << x << ", " << y << ".\n"
<< "Enter the direction you like: (n,s,e,w)" <<std::endl;
}
outside main() function? And why not use
Code:
using namespace std;
(I know it might be your way of writing codes, I just want to make sure I follow everything here.
And Is this the solutions to conio.h problem in Linux?
As I said I am using Robert Lafore's book (Object Oriented programming using C++) from Waite Group, 3rd edition. And it seems he wrote it for Windows. I love the book but I have to find a solution to this conio.h problem.
A small note:
Whenever Microsoft introduces something, it just makes life more difficult. If they can't play by the rules (ISO/ANSI) they should quit!
graemef, I have tried replacing \n with \r and I got the first line (asking about the direction) and nothing happens whenever I press n,e,s,w. but it quits when I use q.
dmail, your code worked fine. I am studying it.
I have a couple of questions:
Why did you have
Code:
void print_question(int const& x,int const& y)
{
std::cout << "\nYour coordinates are: \n" << x << ", " << y << ".\n"
<< "Enter the direction you like: (n,s,e,w)" <<std::endl;
}
outside main() function?
The reason I included the printing of the question in a function is that it is called in two different places in the code I provided, it would be redundant to write the code twice.
Quote:
And why not use
Code:
using namespace std;
(I know it might be your way of writing codes, I just want to make sure I follow everything here.
I could have used the using declaration local to main (global namespace pollution is bad and should be avoided) yet it is as you say just a preference and how long does it take to type "std::"? When working with a large codebase it makes it explicit what you mean, as there could be code in different namespaces which have structures of the same name.
Quote:
And Is this the solutions to conio.h problem in Linux?
The problem is the author is using windows only functions, in my opinion this is wrong as he is meant to be teaching C++.
graemef, I have tried replacing \n with \r and I got the first line (asking about the direction) and nothing happens whenever I press n,e,s,w. but it quits when I use q.
faizlo
I meant add not replace I believe that within ncurses \n is move to the next line but keep the same column whilst \r is move to the first column. However, dmail's solution is much neater.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.