User forums > Help

Parallel project and test field problems

(1/3) > >>

j0k3r:
Hi to everyone.

I'm using C::B 8.02 and i'm sure what i'm asking is pretty trivial, however there are some interrelated issues.

I always write in C++, and i want to be able to debug my programs. First, i discovered (i'm probably wrong here though) i can only debug my code when working in "projects" because i have to set the debug flag, not in single files as i was used to (File -> New -> Empty File). So... it gives me some pain in the ass because my programs are pretty small and i'm doing a bunch of small programs so i have to create a new huge project everytime.

But that's okay, i started doing it that way (although i hope you guys can give me some light here). But now, i'd want to test some portions of codes separately, so i create a new empty file (opens up a new tab) and write a few lines, build...and oops, i realized this new file is saved as *.c whatever i do so it doesn't recognize iostream nor cout obviously etc.

So, to sum up! What's the best methodology to do what i want? Writing small-medium programs without having to create a whole new project and having the option to debug it.

Thank you!

Seronis:
In order to debug you have to use a project / workspace, not just single files.  For situations like this i just have one project named 'quick tests' that i use and paste my code into that projects main.cpp.  As far as your problem with *.c files you must be saving it that way when you create the file, so just name your files extensions properly and problem solved?

j0k3r:
Actually that is what a i did, create a "quickies" project, although i don't like doing it that way and fighting all the time with new files, replacing the actuals in the project for the new ones and so on. I see it kind of whack, why can't you debug a simple file? I don't get it.

Let's say i have this "quickies" project, only one single file named vector2.cpp... i erase its code in the editor and paste a new code (a different one), i save it as "vector4.cpp" because i want to keep it. I click build...and nothing happens, because C::B is building "vector2.cpp" which is the one that's in the project and already built...
So right click and "add files", select vector4.cpp...double click to make sure i'm editing this one and click build...error, detects multiple int main() definitions, one from vector2.cpp and the other from vector4.cpp, so... right click on vector2.cpp "remove this file from project"... and finally it works! But if i want to test a portion of vector4.cpp sepparately i should have to create a new project and blablabla... :?

So, don't you think this is a long and time-wasting way to do it? I'm spending more time navigating through C::B interface than actually working on my code.
Am I doing something wrong or it's just the way to go?  :(

Thank you.

dje:
Why don't you keep a single file in your project with main where you put your code to debug and export the code you want to keep in other files that are not members of the project?
Quite fast I find...

Dje

zabzonk:
Another alternative is to give each of your single files its own main, which does whatever you would have done in the real main. Give them distinct names:

int vector4_main( int argv, char **  ) {
   // your stuff
}

Then have a single file called main.cpp which contains a real main() that looks like this:

extern int vector4_main( int, char ** );
int main( int argc, char ** argv ) {
   return vector4_main( argc, argv );
}

Keep all of your small files in a single project and when you want to play with a particular one, change the name of the xxxx_main() that the real main calls.

Navigation

[0] Message Index

[#] Next page

Go to full version