I am trying to build a ping-pong game on my mac using C++14 (g++ in terminal) and I am getting this error:
use of undeclared identifier 'kbhit'
here is the code: https://github.com/DemonJAZ/GamesC
The function is in GameManager, class named Input.
Since there is no sentence with a squiggly mark in the end, I took a liberty to invent a couple of my own.
Why am I getting this error?
There is no kbhit function in the C++ language.
Why am I seeing people using it all over the place? Why does it work for them?
They are using it on Windows. It's a Windows function. You are on Mac OS X.
I like to be able to use this function. What should I do?
There are several options.
Develop on and for Windows,
Find a port (i.e. a re-implementation in a different environment) of this function that works on Unix-based systems. I'm sure someone somewhere wrote one. Start with https://www.google.com/search?q=kbhit+mac and if this doesn't help, try https://www.google.com/search?q=kbhit+linux. In fact https://www.google.com/search?q=kbhit+ncurses will probably return the best results, but it's kinda hard to guess if you don't know exactly what to look for.
When in Rome do as Romans do. Write to the widely used Unix terminal API known as curses (you probably want the ncurses version).
Related
I am having a weird bug in using netbeans and C/C++ plugin along with that.
When I copy/paste a code, it gives me error Unable to resolve identifier on every function (including main). But if i manually type same code/program, its all good and working and compiles/runs perfectly. Can anyone explain that to me? Normal java projects work just fine (the copy/pasting code doesnt give any sort of error), its just the problem with C/C++ projects (havent tried others yet). I not only want to know solution, but also the possible cause (out of curosity).
EDIT:
Here's an example of an infinite loop i was trying (say for fun? lol)->
#include <stdio.h>
int main()
{
char a;
for(a=32;a<128;a=a+1)
printf(“%3d = ‘%c’\t”,a,a);
return(0);
}
This program goes on displaying keyboard characters and their ASCII codes over and over endlessly. If I manually type this program, its all good. If I copy paste this code, it gives me error as stated above (on every variable and function. For ex- "Unable to resolve identifier" on main function).
Some backstory (not related to problem really)...
Actually I am using netbeans because of its features. The way it tells about a lot of errors right on real-time bases, its auto bracket closing feature, the ui cleanliness (or maybe I am used to it). I just started leaning C a while ago, though I am quite advanced in java (the reason I have netbeans, I dont use eclipse because of drag and drop interface, which basically cuts a lot of time for me. I know there are plugins now that enable that in eclipse too, so I might give it a try but for now I am used to netbeans' interface). My teacher recommended me bloodshed C/C++ (which i didnt like, its like a plain notepad with just the ability to compile) or turbo C (which proves my teacher to be of ancient times). And he told me visual studio was too advanced for me right now. So i decided to stick with netbeans. Except this problem, everything is working perfect as of whatever I have tried right now.
Also, as of side note, do you guys think me sticking with netbeans for C/C++ for now is ok (ok in sense I am wondering about the cons)? I think I'll move on to visual studio later....
The code you have in your question won't compile on any compiler. Why?
You are using curly quotes here:
printf(“%3d = ‘%c’\t”,a,a);
“ and ” are different from ". Use " instead of “ and ” to fix the problem.
‘ and ’ might also cause problems. Replace them with '
Previosly i used turboc++, but recently shifted to codeblocks and sometimes i also use notepad (i compile code using gcc via command promt, though possible in codeblocks). Now previously, in turbo c++ i used ctrl+F1 to get help for particular function or keywords or headerfiles etc, by keeping the cursor line on the keywords, the help is regarding the description of what the function does, whatever etc. Now in gcc(or in code::blocks) i want to know is it possible to get the help for, lets say for a perticular keyword, using some commands in gcc under command prompt?
(not sure, but i heard it is possible in clang).
What you're looking for is an IDE.
There are many, many choices. I'd strong recommend looking at Eclipse CDT:
http://www.eclipse.org/cdt/
http://www.ibm.com/developerworks/library/os-eclipse-stlcdt/
PS:
The "C:B" referred to above is "Code Blocks". That might also be a good choice for you - check it out, too:
http://www.codeblocks.org/
I've had to use a very old library written some twenty years ago. I get it to compile almost completely, except for one part that uses a REGS union. From the Google searching I've done, REGS is a part of interrupt handling in the DOS.h file. Well, looking at the modern version of DOS.h, one does not see any REGS definition.
Some posts around the Internet said something about it being unique to either the Borland or Turbo compilers, but this code was written to work under many different compilers.
Any ideas what I should do? Is an old DOS.h file floating around that might work?
Using: Visual Studio 2010, compiling from command line.
Pretty much the only thing you can do is figure out what they're doing with the REGS, and do (as close as you can) to the same thing at that higher level. In most cases, REGS were used to invoke DOS functions, most of which have equivalents that can be invoked as normal functions under Windows. Others were to use BIOS functions, which (again) mostly have functions to accomplish the same.
Without knowing what was being accomplished with the REGS, however, it's impossible to guess what the replacement would/will be.
Creating the REGS union is the least of your problems. Applications can't simply call interrupts whenever they want under a protected-mode operating system. And if they try, they'll be stopped by the system.
A better approach is to look for ways to accomplish it using the Windows API.
EDIT
The above comments assume you are doing modern-day Windows development, which I guess was an assumption. Other than the tools you are using, you really haven't said a thing about the type of application you are developing (command line, windowed, 32-bit, 64-bit, etc.), in addition to not saying anything about the task you're trying to accomplish.
If you are developing for 16-bit DOS, then you can still do interrupts.
This is basically a duplicate of:
Netbeans or Eclipse for C++?
But, that question as 3+ years old, and a lot has changed since then.
I have a large code base with a custom (but Makefile based) build system. The areas I am specifically wondering about include:
Syntax highlighting
Code navigation.
Code hints.
"ReSharper style" code helpers.
Documentation integration.
Debugger UI and features.
Has anyone had the chance to evaluate both Netbeans and Eclipse?
EDIT: As a followup question, are any of the Netbeans users here concerned with its future given Oracle's recent bad history with "open" efforts? (Open Solaris, MySQL, Open Office)
Thank you
I cannot comment on eclipse, but on netbeans 7 I will say things that are very important for me and that work fine so far:
code completion, go to declarations
pkg-config automatic include management for parsing
stuff that sometimes works and sometimes don't
find usages, sometimes it might fail to find usages in other open projects
debugger sometimes gets confused with unittest-cpp macros and it will not go on the appropiate line
stuff that are not yet working and i care deeply:
C++0x syntax highlighting (auto, lambdas, enum class, variadic templates, none of them are recognized by the built-in parser)
stuff that is not quite working but i could not care less:
git integration. I enjoy using git from command-line so this is a non-issue
in all, the IDE is very usable. I hope to have a chance to try out latest cdt on Indigo Eclipse, but so far i haven't that much of a real reason to investigate
I cannot comment on Netbeans, but I can offer you information on Eclipse. I work with C++ on UNIX systems, and I have started to use Eclipse when exploring large code bases that I know little about. I don't use it to build, but it would be easy to integrate our build system with it as one only needs commands.
Eclipse has most of what you are looking for: (I'm speaking of Eclipse/CDT)
Not only can you completely customize your syntax highlighting, you can also have it format the code with templates. My company has a code standard for spacing, tabs and formatting of functions and conditional code, and with little effort I was able to modify an existing template to meet our code standards.
The navigation is not bad, if you highlight and hover over a variable, it shows you the definition in a small pop-up bubble. If you do the same for a type, it will you show you where the type is defined. For functions, it will show the first few lines of the implementation of the function, with an option to expand it and see the whole function. I find all of these nice for code discovery and navigation. You can also highlight a variable, and use a right-click menu option to jump to its declaration.
I suppose by code hints you are referring to something like intellisense? This is the main reason why I use Eclipse when looking over a large code base. Just hit the '.' or '->' and a second later you get your options.
The debugger UI is quite capable. You can launch gdb within the tool and it allows you to graphically move through your code just as you would in a tool like ddd or Visual C++. It offers standard features like viewing registers, memory, watching variables, etc.
That being said, I have found some weaknesses. The first is that it doesn't really strongly support revision control systems outside of CVS and SVN very easily (integrated into the GUI). I found a plug-in for the system we use at my company, but it spews XML and Unicode garbage. It was easier to just use the revision control on the command line. I suspect this is the plug-in's issue and not Eclipse. I wish there were better tool integration though.
The second complaint is that for each project I have to manually setup the include directories and library paths. Perhaps with an environment variable this could be circumvented? Or I may just do not know how to set things up correctly. Then again if it is not obvious to a developer how to do this, I consider that a weakness of the tool.
All in all I like working with Eclipse. It is not my main editing environment, but I appreciate it for working on large code bases.
I'm a huge fan of Netbeans. I am in a similar situation to yours, but creating the project was very easy. Just point Netbeans at where the code is checked out and it figures out most things for itself. I rarely have to do any configuration. One thing to note though, if your tree is very large, it can take some time to fully index - and while it does, memory and cpu will be hosed on the box.
The integration with cvs is awesome, and the Hudson integration is very cool for CB. I've not used Git myself, though I should imagine it's a no-brainer.
One thing that does irritate me no end is that it does not behave very well with code relying heavily on templates. i.e. shows lots of warnings and errors about types not being found etc.
I have not used the latest version of Eclipse, I tried the major release before the current one and gave up because it did not have the same smooth project integration with the makefiles etc. I find it's not as nice if you don't want to use it's make system - though I could be wrong.
I don't use any of the code formatting provided, I instead prefer something like AStyle instead. I know that NetBeans does a good job with Java - but have not used it for C++. CDT I seem to remember doing some odd stuff with indentation when formatting C++ code - esp. if templates are involved - but that was atleast two years ago.
Hope some of it helps - the best way to do this is to download and try for yourself and see what works for you. Anything we tell you is purely subjective.
I used to work with Netbeans with MinGW, I Just tried 7.0.1.
I currently use Eclipse Indigo with CDT and MinGW - It's better performance wise (less CPU & Memory).
Netbeans creates a makefile to compile all the time,
In Eclipse you can build directly with the CDT-Toolchain or use Makefile - Eclipse is more flexible.
Debugging: Netbeans might be better in Solaris/Linux.
I Personally rather eclipse over Netbeans, I think eclipse is more professional.
One particular issue that causes me quite a lot of grief with Netbeans 7.0 is that it tends to want to work with utf8 files, and not all of out c++ projects are utf8. It will issue a warning about opening such a file, and if you do open it, will corrupt said file, which is a pain.
I've not found out how to properly make netbeans handle this. Apparently the encoding can be changed, but for the entire project. So presumably changing it to us-acii would stop this problem, although non ascii characters wouldn't display properly.
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Have you used any of the C++ interpreters (not compilers)?
Hi,
I am currently learning C++ and a beginner in programming in general. I've been trying to write some code to a few programming problems from the book I'm using. What I find is that often I make mistakes in what I write and those mistakes come up when the program is run. Its usually quite obvious where in the program I've gone wrong when there is regular output. But in a long computation I'm often not sure why a particular code has acted a certain way. I've also looked at Python recently. Python works with an interpreter, which can take any piece of Python code and compute its output.
I was wondering if there was something similar for C++. Right now when I want to check a line or block of code I have to comment out a lot, save it, compile it, and then run it from a command line. And I have to do that many times for a single error until I've solved it. Is there a way to type code into an active terminal which would run code and show me output? What would be better still would be a way to select a block of code (like you select text) or multiple blocks (to see how a function is being handled) within the IDE and click run to run just that block of code and see its output without having comment out irrelevant lines or to save the file. The compiled code could just reside in memory.
CINT is a c & C++ interpretter that accepts nearly all valid C++. Unfortunately many Linux distros do not offer it, and you'll probably have to build it from source... and that is a non-trivial task.
Typically a debugger is used to step through code line by line, starting at a chosen breakpoint, and keep watch of all variables/values.
Unit testing is a technique to test smaller pieces of code.
A stepping debugger, as found in most IDEs will help you with this.
Here (for example) is a description of how to set the Execution point in In Visual Studio, which sounds like what you want to do.
For certain situations, the "Immediate Window" may be of use to you. It allows you to type in expressions to evaluate immediately.
Rather than just running individual lines independently, or relying on print statements to tell you the state of whatever variables you have decided to print, you can use the debugger to run to the point of interest (where you will have set a breakpoint), then you can examine the state of any in-scope variables, or even alter the normal flow of the program.
There are some solutions that try to do this - the ones I know are Ch and TextTransformer.
However, I doubt that this works very well. C++ is not at all designed to run as an interpreted language.
One of the problems is that C++ is very, very hard to parse. And this makes it very hard to provide certain types of tools that are usual for other languages. For example, I don't think there is any C++ refactoring tool that really works well.
C++ is a compiled language not like python. But there are few c/c++ interpreters out there but not sure about their features. Check these out: Ch interpreter and CINT
If you really want to learn c++ please do not use the c/c++ interpreters.
If you insist on using a interactive interpreter there is since a long time CINT which is the default interpreter used in the ROOT project. It got better over the years, but still has only limited capabilities when dealing with templates. Also, there is a move to replace it with a JIT compiling interpreter based on clang inside the ROOT project.
If I were you I would learn how to run compiler and an interactive debugger like suggested in some comments already.