Forum

> > Off Topic > C++ Tutorial
Forums overviewOff Topic overviewLog in to reply

English C++ Tutorial

128 replies
Page
To the start Previous 1 2 3 4 5 6 7 Next To the start

old Re: C++ Tutorial

archmage
User Off Offline

Quote
I used a vector to hold a pointer to each instance of a class, but failed. Could you give me a small example?

old Re: C++ Tutorial

Flacko
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
std::vector<yourclasstype>vec;
yourclasstype var1;
yourclasstype var2;
vec.push_back(var1);
vec.push_back(var2);
for(int i=0; i<vector.size(); i++)
{
	vector[i].a = 0;
}

old Re: C++ Tutorial

archmage
User Off Offline

Quote
Thanks. I need to know what <<, >>, <<=, and >>= do.
Ex:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
short sqrt(short num) {
        short op = num;
        short res = 0;
        short one = 1 << 14; // The second-to-top bit is set: 1L<<30 for long
 
        // "one" starts at the highest power of four <= the argument.
        while (one > op)
            one >>= 2;
 
        while (one != 0) {
            if (op >= res + one) {
                op -= res + one;
                res = (res >> 1) + one;
            }
            else
              res >>= 1;
            one >>= 2;
        }
        return res;
    }

res = (res >> 1) + one;
one >>= 2;
short one = 1 << 14;


Edit:
Nvm I think I found it. Is it
1
2
>>	n1/2^n2
<<	n1 * 2^n2
and the >>= and <<= just assign the values to variables. Correct?
edited 1×, last 01.10.10 01:34:04 am

old Re: C++ Tutorial

archmage
User Off Offline

Quote
I am using code blocks because when I compile with VC++ the apps always require a DLL. Where are the include & lib directories for code blocks?

Also why are these different
1
2
-- Lua
a = 5 * 2^2

1
2
// C/C++
b = 5 << 2
a = 20
b = 52

Edit
Nvm I was using it in cout
1
std::cout << " 5 << 2 " << 5<<2;
Which should print 52

old Re: C++ Tutorial

Flacko
User Off Offline

Quote
Try:
std::cout << " 5 << 2 " << (5<<2);

I don't remember about code::blocks, I had it in my old computer which is lost almost forever

old Re: C++ Tutorial

Flacko
User Off Offline

Quote
I use wxDev with GCC mingw 3.4.5 (VERY old) I might try to update it later...

old Re: C++ Tutorial

archmage
User Off Offline

Quote
Is there a good, easy to use, compiler that does not have an IDE? So I write my code with something like n++ then open a command prompt type a few commands and that is all?

old Re: C++ Tutorial

Lee
Moderator Off Offline

Quote
Try mingw, my usual compilation steps consists of just a few steps:

1
2
g++ -c a.cpp, b.cpp -I"include path"
g++ --shared a.o, b.o -L"library path" -lsomeLibrary

At its simplest however, we can reduce this to

1
g++ hello.cpp -ohello

old Re: C++ Tutorial

archmage
User Off Offline

Quote
Lol I just found that. And I have a question. It says I need libgcc_s_dw2-1.dll with one of my compiled programs. All of my programs have worked until now. Des it have something to do with the fact that I have included libsfml-system.a to run an sfml program?

old Re: C++ Tutorial

Lee
Moderator Off Offline

Quote
That's completely normal. Programs linked against various major c++ libraries require this as a dependency, including but is not limited to: boost, QT, and sfml. Just drop the dll file into the running directory. I had the same exact issue while working on a project which linked against the QT-core library.

old Re: C++ Tutorial

archmage
User Off Offline

Quote
Alright it owrks now, but is there a parameter to remove the console?

old Re: C++ Tutorial

Lee
Moderator Off Offline

Quote
*Sniff*
Our little Dark Bit is growing up so fast, he's finally becoming Dark Byte *sniff-and-wipes-nose*

old Re: C++ Tutorial

archmage
User Off Offline

Quote
Lee has written
*Sniff*
Our little Dark Bit is growing up so fast, he's finally becoming Dark Byte *sniff-and-wipes-nose*

lol

old Re: C++ Tutorial

Flacko
User Off Offline

Quote
I'm having problems running it, could you statically link gcc and stdc++?
Just add -static-libgcc and -static-libstdc++

old Re: C++ Tutorial

archmage
User Off Offline

Quote
Alright I will.
Here it is http://www.filefactory.com/file/b3c94bf/n/output.exe

Edit
The bullet image does not appear what is wrong?
More >



Edit
Click the link -> Epic Tic Tac Toe

Is it possible to not need all those DLLs?
edited 4×, last 08.10.10 02:46:55 am
To the start Previous 1 2 3 4 5 6 7 Next To the start
Log in to replyOff Topic overviewForums overview