C++ (Error Message) - c++

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.

Related

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

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

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 '

Stepping through C++ programs like in python and R

Python and R overs a friendly way for one to understand the source code written in these languages and users can stop at a given point and inspect the objects (as objects in these languages can be printed in a user friendly way while debugging).
For C++, I don't know if there is similar way. I currently don't use IDE. I know the C++ source code can be compiled with the -g option to allow the use of gdb. But this is still much more difficult than what is in python and R. Does anybody know what might be the best to step through C++ source code and inspect objects when necessary (for code understanding purpose)? Thanks.
Because Python is an interpreted language, you can have this friendly "debugging experience". C++ is a compiled language so when the executable is running, the run-time knows nothing about the source code. That is why we have to use a GDB or something that can help us to associate the binary and the source code.
So I think you have to get familiar with GDB or just pick a nice IDE.
Eclipse is quite good! You can do anything with it because there are so many plugins for it.

Is there such a thing as a C++ interpreter? [duplicate]

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.

Is there a decompiler that will work on Visual Studio 6 C++

I have a project that I am trying to fix from a guy that left (let go) from my company. He has violated every fundamental principle of software engineering, not using source control, not backing up the source before you make more changes, etc. etc.
I need to make changes to an application that is in the field and I don't have the original source code, but I have an executable. What I need is a decompiler that will decompile a Visual Studio 6 C++ application and provide me with some type of source code. Anyone got any ideas.....
Well there's the Decompiler from Hex-Rays: https://www.hex-rays.com/products/decompiler/
It is pretty good for the fact that it is creating C code from Assembler but it works pretty good. It's also pretty expensive
Edit: Additional note it is combined with IDA Pro the pretty well-known disassembler from them. That already can show you a lot of information in the combination with the decompiler it is even easier to reverse code.
I've used RecStudio (rec22) and IDAPro to try and decompile a C++ project, together they probably wouldn't have been enough to do the job I had except that I worked out the demo project the program was based on so they gave just enough info that I could make something like the same project again.
In the end one other thing I was doing was compiling code that I thought matched and checking that I got the same result in the decompiler.
Good Luck.
Decompile to what - assembler?
There isn't anything that is going to give you meaningfull C from an exe.