How to program in C++ properly (using libraries and stuff and "what's wrong with me!!?"))

Hi


i'd like to learn to use C++ for my homework assignments (instead of always using Octave). the problem is i've been unsuccessful at using "libraries" outside of the standard ones (iostream, fstream, stdlib are the standard ones? or what do you call them?).

i've been using codeblocks and devc++ following a beginning c++ textbook, and tried to use openmp, opencv, and this cimg.h thing (for my image processing class), but have been unsuccessful.

can someone explain to me how to use other "libraries"?

i tried to follow the tutorials from googling, but everyone's using different "ide"'s, on different os's, with different "compilers", no luck there.

usually what happens is:
- i have to add the "include xxx" statement(s) (i really dont know what to add, for opencv and openmp, ppl "include" so many different possible things), or "add using namespace xxxx"
- i have to add "environment variables" and "paths" in my computer (i'm using windows 7).... i think this is where the "compiler" naturally looks at to find the libraries?
- have to add some special commands when i compile (if in command line i do like "g++ -somethings -something ...", in codeblocks i go to fiddle with the "compilers settings" and fail (of course).



anyway... i think overall i'd like to adopt an environment to program in C++ and use "libraries"(?) properly if i have to.

i was able to use openmp on our school's workstation, but there i have to use vim, so the process is slow (open vim, edit, save, exit vim, compile and run, reopen file in vim, etc), is there a way to be like a windows IDE to have a separate window to see the results of my program? or a faster short-cutty way to execute my current vim-c++-programming mode.



i'll also try to talk to some classmates to see if they can help, but i dont know any of them, and they all seem really unfriendly, so good luck me. otherwise it's back to using the Octave calculator for me.




Thanks, and let me know where i should start really,
od

I assume this link will be of much help to you.

http://cplusplus.com/reference/clibrary/

I am also a beginner, so when I start my homework, I always use the libraries
:
<cmath> for math functions
<cstdlib> for anyone to open your files
<string> for any use of strings in your programs
<iostream> for cin & cout
<fstream> for files
<windows.h> for any use of coloring text and backgrounds

usually the start ( & end) of my programs will look like this

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <fstream>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <windows.h>
using namespace std;

int main ()
{
// Enter in code here.
system ("PAUSE");
return EXIT_SUCCESS;
}


Hope this helps you while learning C++.

X RadCod3Win

P.S. If you ever need help, always ask your teacher ! If you do not want to talk face to face, you can always e-mail the teacher, or look up answers online.
can someone explain to me how to use other "libraries"?


1) Download the library source code.

2) Put the source somewhere you'll be able to refer to it later. Like designate a separate directory for libraries or something.

3) Figure out how to build the library. This varies from library to library. Most have tutorials or guides on their sites to walk you through the process, and some (C libs mostly) do not require the lib to be build manually at all. This difficulty of this step can vary greatly depending on the lib.

4) Configure your IDE and give it paths so it knows where to look for #include lines and for linker files. This varies from IDE to IDE. You probably should not be modifying any environment variables to do this... unless you're not using an IDE.

5) In programs that use the lib, you will need to #include <libs_header_file> to access the stuff in the lib

6) In programs that use the lib, you will also need to link to the library binaries. This is also a setting in your IDE which varies from IDE to IDE.


I can't get into any more details without getting into specific IDEs. And I'm only familiar with a few of them.

but there i have to use vim, so the process is slow (open vim, edit, save, exit vim, compile and run, reopen file in vim, etc)


I'm no expert with vim, but if it's slow you must be using it wrong. There is no reason why you'd have to exit vim to compile and run a program.

That said... it's certainly easier (imo) if you use a proper IDE. Compiling and running is as easy as pushing a single button.

is there a way to be like a windows IDE to have a separate window to see the results of my program? or a faster short-cutty way to execute my current vim-c++-programming mode.


I'm sure there is. From what I understand, there is very little that vim cannot do. However, I cannot help you out in this area since I have never used it. Hopefully someone else can chime in on this one.
thanks you guys,

do you have any IDE's that you recommend?

Topic archived. No new replies allowed.