Forum

> > Off Topic > C++ Tutorial
ForenübersichtOff Topic-ÜbersichtEinloggen, um zu antworten

Englisch C++ Tutorial

128 Antworten
Seite
Zum Anfang Vorherige 1 2 3 4 5 6 7 Nächste Zum Anfang

alt Re: C++ Tutorial

archmage
User Off Offline

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

alt Re: C++ Tutorial

Flacko
User Off Offline

Zitieren
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;
}

alt Re: C++ Tutorial

archmage
User Off Offline

Zitieren
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?
1× editiert, zuletzt 01.10.10 01:34:04

alt Re: C++ Tutorial

archmage
User Off Offline

Zitieren
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

alt Re: C++ Tutorial

Flacko
User Off Offline

Zitieren
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

alt Re: C++ Tutorial

Flacko
User Off Offline

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

alt Re: C++ Tutorial

archmage
User Off Offline

Zitieren
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?

alt Re: C++ Tutorial

Lee
Moderator Off Offline

Zitieren
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

alt Re: C++ Tutorial

archmage
User Off Offline

Zitieren
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?

alt Re: C++ Tutorial

Lee
Moderator Off Offline

Zitieren
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.

alt Re: C++ Tutorial

Lee
Moderator Off Offline

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

alt Re: C++ Tutorial

archmage
User Off Offline

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

lol

alt Re: C++ Tutorial

Flacko
User Off Offline

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

alt Re: C++ Tutorial

archmage
User Off Offline

Zitieren
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?
Mehr >



Edit
Click the link -> Epic Tic Tac Toe

Is it possible to not need all those DLLs?
4× editiert, zuletzt 08.10.10 02:46:55
Zum Anfang Vorherige 1 2 3 4 5 6 7 Nächste Zum Anfang
Einloggen, um zu antwortenOff Topic-ÜbersichtForenübersicht