Commands not identified when copy/pasted, but are identified when manually written - c++

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 '

Related

C++ in Netbeans: many senseless "unexpected token" hints

I am very new to coding C++ and to using the Netbeans IDE. Worse yet, I'm on a Mac (but I can't imagine that's the source of the issue this time).
The IDE is giving me countless nonsense "hints" as in red exclamation mark symbols, most of which say "Unexpected token" for things like ';' at the end of a statement or '=' in a statement. These are of course ridiculous because, as I understand c++ so far, they are necessary for even the most basic statements!
screenshot here
What could possibly be causing this and how do I get rid of the hints or, preferably, fix something if there is an error somewhere?
Delete your Netbeans cache. In my case the problem when away when I did this. I think I initially ended up in this state because my C++ project was under a Java project. After separating the two the error was still present even with a clean/build. Deleting the Netbeans cache got rid of the problem. Even if your situation is different you should try this. Clearing the Netbeans cache once in a while fixes a lot of issues.
Tyler,
I'm going to go out on a limb and guess that you've got your Net beans ide setup to use another language other than C++. Remake the project and make sure your using c++
I had the same issue.
The issue was, I wrote C++14 code, in the C++ project.
To resolve this:
- Create a C++14 project (Select from the drop down, while creating the project)
- Add existing C++ files to it
Hope that helps.

Debugging C++ on Windows

I'm trying to implement a Suffix Trie to search strings using C++ for a programming assignment. Now I've started coding things with Vim/Ubuntu on a virtual machine (since I run windows), partly because it's encouraged by our lecturer not to use IDEs and compile things manually, and partly because the VM is too slow to run a decent IDE anyway.
But my program has grown quite large and I need to debug things. I've grown quite fond of both Eclipse's and CLion's debuggers in the past, so I decided to copy and paste my workspace to a windows directory, just for debugging.
I’m using C++11 and MinGW as a compiler, and programs run just fine:
But when I tried to debug the program, I got the message:
So I decided to try debugging in Eclipse instead. This time it sort of worked, but it isn't treating my std::string objects as strings, but rather as just objects with lots of properties in them:
This is obviously a problem since I'm dealing a lot with std::strings. Now I've read online that this is related to the whole pretty printers thing I got with CLion, but I haven't been able to find anything which tells me how to get things set up with MinGW. I'd appreciate any advice.
I was trying to figure out the same thing few days back. After Googling for hours and compiling all the stuff into one place, I have created a detailed post which might here.
Here is the link: https://dev.to/abhinav1602/how-to-run-vs-code-c-debugger-on-windows-4d3

C++ (Error Message)

Gday guys and gals. I am an absolute newbie for C++, and not overly computer literate, ok not at all!! (My last computer code attempt was as a kid in 1991, with a 386 DOS machine, so 25 years have not been kind). Anyway to the point. I have just donwloaded a C++ compiler and when on the dos prompt using bcc32c it finds the program, but brings and error message. (Error: no input files). How do i fix this? please, if this is an easy question, or has been asked 1000 times before, please just humour me, or point me in the right direction. Any help would be greatly appreciated. Cheers.
It sounds like you might be confused as to what the compiler does. The compiler, in this case bcc32c, compiles your source code files into an executable, you need to write your source code in a text editor or an IDE first.
The error message is indicating that you need to specifythe path to the source files that you want to compile, for example, if we assume your code is stored at "c:\mycode\main.cpp" your command would be "bcc32c c:\mycode\main.cpp"
You may have an easier time working with an IDE like Visual Studio or Code::Blocks, command line compiling is not very user friendly, especially for people who are new to coding.
Unless you are dead set on learning C++, I would suggest learning a simpler language like Python first, C++ has a very steep learning curve! Python has a simpler syntax than C++ and is an interpreted language so you won't need to compile anything.

Netbeans doesn't show error messages when it should

I've been re-learning c++. I haven't coded in c++ for quite a few years, although I really like the language, so I decided that I would re-learn it. When I first learned c++ I used dev c++ as ide. Nowadays it is seriously deprecated and I decided to use netbeans since it's the one I use for java and I'm quite accustomed to work with it.
I've set everything up in the ide, downloaded the plugin and installed the compiler and stuff. I'm having, though, a very frustrating time with the warnings of netbeans. The code itself compiles and runs fine, but netbeans doesn't seem to work very well. For example, if I create a new source file and before any compiling I write the usual using namespace std; there's a red wavy underline under std where netbeans gives the following error message "unable to resolve identifier std". If I then compile the code it disappears and everything is fine so it's not a serious problem , although it's quite an annoying behaviour.
Another, not so simple, error is if I declare a variable say int x;. I then use the variable x throughout the code, everything's fine. But if by some reason I delete the declaration statement (sometimes it happens), the rest of the code, which should by full of error messages, appears has everything's fine, no wavy red underlining...
It appears to me that netbeans only notices the errors after I compile the code... Does someone know how to fix this behaviour?
This is normal (there is nothing wrong with Netbeans).
When editing java code, the IDE parses the code as you type and corrects immediately (or, with a relatively short delay).
When editing C++, the language is a lot more complex than Java, and while the IDE finds some errors (and underlines them), a lot of them are in code that is too complex to be parsed instantly (C++ compilation is difficult to do, and even more so, to do fast). As such, Netbeans relies on you compiling the code to update error information.

As of 2011: Netbeans 7 or Eclipse Indigo for C++?

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.