|
There is no "array" in STL. Do you mean Boost Array?
|
|
|
|
|
I wonder if he means the difference between vector and raw arrays?
Kevin
|
|
|
|
|
I mean usind an simple C++ array and STL vector
|
|
|
|
|
Here[^] is a pretty long discussion about that.
|
|
|
|
|
|
hi,
in the code below, i highlighted my points of interest. the declaration of the template function make takes a const char[]. in the call to this function, why is < deque<char> > inserted before the actual parameter? i.e. it's not in the signature and the parameter is not a typename but an explicit const array of characters.
thanks!
<br />
#include "stdafx.h"<br />
<br />
#include <iostream><br />
#include <cassert><br />
#include <deque><br />
#include <algorithm>
using namespace std; <br />
template <typename Container><br />
Container make(const char s[])<br />
{<br />
return Container(&s[0], &s[strlen(s)]);<br />
}<br />
<br />
int main()<br />
{<br />
cout << "Demonstrating generic find algorithm with "<br />
<< "a deque." << endl;<br />
deque<char> deque1 = <br />
make< deque<char> >("C++ is a better C");<br />
<br />
deque<char>::iterator<br />
where = find(deque1.begin(), deque1.end(), 'e');<br />
assert (*where == 'e' && *(where + 1) == 't');<br />
cout << " --- Ok." << endl;<br />
return 0;<br />
}<br />
I am a SysAdmin, I battle my own daemons.
|
|
|
|
|
This is the template function declaration.
template <typename Container> Container make(const char s[])<br />
And your example translates to:
template < deque<char> Container> Container make(const char s[])<br />
Which actually translates to:
deque<char> make(const char s[])<br />
{<br />
return deque<char>(&s[0], &s[strlen(s)]);<br />
}<br />
"const char s[]" is just a parameter to the function make, which in your case returns an object of type deque<char>.
- S
50 cups of coffee and you know it's on!
Rock the Vote: John Simmons / outlaw programmer for '08.
|
|
|
|
|
thanks but i was asking about the call to the function template. if you noticed the second highlighted line, the call specifies <deque<char>> before the actual const char array parameter. This <deque<char> is not part of the signature after the function name. But somehow, it is needed to determine what type the instance of the template function is.
cheers!
-- modified at 1:18 Tuesday 7th August, 2007
I am a SysAdmin, I battle my own daemons.
|
|
|
|
|
By calling make< deque<char> >, you're telling the compiler which template to use, since it can't "infer" the template type from from the arguments.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
For that particular function, the type of Container isn't indicated by the parameters. IOW, if you wrote:
make("C++ is a better C"); how would the compiler know what type of Container you wanted to make?
|
|
|
|
|
Is this possible? In particular, I just installed copypathext.dll from here: http://www.codeproject.com/shell/copypathext.asp. I'd like to invoke the commands in that dll instead of using the context menu.
|
|
|
|
|
|
That was quick, thanks. The routine I want to run was explained in the article as IContextMenu::InvokeCommand. There was also this: The code consists of an ATL DLL project with a single class, CCopyPathContextMenu. Like all context menus, it implements the IContextMenu. What would be the syntax for the entry point to pass to rundll32?
|
|
|
|
|
Mmmm - that's more tricky, if not just plain impossible with rundll32 . It lets you call a C function from a DLL. However, you're wanting to call a COM method. Which means you need a COM object reference, and I don't know how you'd create a COM object on the command line without just writing your own code (in an executable) to do so.
Sorry
|
|
|
|
|
The following code will generate a random integer, then format this in uppercase hexidecimal, and then copy it to a std:string. Is there a better way of doing formatted output to a std:string ?
std::string sRandomString;<br />
std::ostringstream osRandomString;<br />
int x;<br />
<br />
x = (rand() << 16) | rand();<br />
osRandomString << std::hex << std::uppercase << x;
sRandomString = osRandomString.str();<br />
<br />
Why does it not work correctly when I use std::ostringstream::hex and std::ostringstream::uppercase ?
If I want to create multiple random strings by using a loop, am I right in thinking I just need to place the following line at the end of the loop, so that the next string generated will overwrite the previous string in the stream, instead of being appended to it ?
osRandomString.seekp(0);
Is it necessary to place << endl or << ends after x where the formatting takes place ?
eg. osRandomString << std::hex << std::uppercase << x << endl;
If yes, should I use endl or ends ?
|
|
|
|
|
If you want to use STL strings, you might want to look at Boost.Format[^]. Then you could do something like:
osRandomString = boost::format("%X") % x; It's basically a type-safe and more C++-ish version of printf. And there's so much other good stuff in Boost as well that you're doing yourself a favour by using it (IMO!).
|
|
|
|
|
Dear ATL C++ / graphics people,
I already searched the forums, but found no answer, just questions to
this topic. So I'll try my luck and post my question:
I am searching for an easy way to load a sequence of jpeg files (which
form a video) into memory and play them like a video. I furthermore
want to react on a keypress by drawing a frame into the current jpeg
in the sequence and saving it to disk/memory (maybe to disk not during
play, but after it, since there should not be delays, performance
does matter!). Is there a simple way to do this with the ATL already?
A little navigation functionality would be great (jumping to specific
frames, having a slider, Play/Stop Button etc.)
Did anyone already do something like that? I want to use pure ATL
and no MFC since I have a guideline to use ATL only.
Would be nice if that would be possible and anyone could help.
Best regards,
Peter.
|
|
|
|
|
am a new member and i will want you to hlp me.I have been tryin to write a c++ code for this number puzzle for a while but eventually i used java cos i knw it a little bit. i would appreciate if any body can hlp me in writin it c++ proram and evn completing.ppplllllllllllleeeeeaaaaaaaaaassssssssssssssssssseeeeeeeeeeee
here is the basic code that will help an user play, i am still trying to automate it, if anyone is able to finish it please let me know
import java.applet.Applet;
import java.awt.Color;
import java.awt.Event;
import java.awt.Graphics;
/** **************************************************************** */
// <applet code="puzzle" width="100" height="100">
/** **************************************************************** */
public class Puzzle extends Applet {
private static final long serialVersionUID = 1;
public Piece pieces[] = new Piece[16];
int i, x, y, currentValue;
int startX = 50;
int startY = 50; // start pos of puzzle
int rowSize = 4;
int pieceWidth = 50;
int pieceHeight = 50;
private int blankPiecePosition;
Graphics graphics;
SimplePuzzle simple;
RandomValue randomValue = new RandomValue(1, 16);
public void init() {
graphics = getGraphics();
/* INITIALIZE THE BLANK PIECES */
x = startX;
y = startY;
for (i = 0; i <= 15; i++) {
currentValue = randomValue.getRandomValue();
// currentValue = i+1;
/* SET THE INITIAL POSTION OF THE BLANK PIECE */
if (currentValue == 16) {
blankPiecePosition = i;
}
// pict = getImage(getDocumentBase(),image_name+currentValue+".gif");
pieces[i] = new Piece(i, currentValue, graphics, x, y, null, this);
x += 50;
if (x > 200) {
x = 50;
y += 50;
}
}
/* CREATE A NEW SIMPLE PUZZLE */
simple = new SimplePuzzle(15, this);
resize(pieces[0].width * 6, pieces[0].height * 6);
}
public void start() {}
public void stop() {}
public boolean mouseDown(Event evt, int x, int y) {
int rel_x, rel_y;
int click_piece;
int cur;
// FIRST CHECK IF THE POINT IS INSIDE THE PUZZLE
if (isPointInside(x, y)) {
// NOW GET THE CLICK PIECE
rel_x = (int) (x - startX) / pieceWidth;
rel_y = (int) (y - startY) / pieceHeight;
click_piece = rel_x + rowSize * rel_y;
// IF THE CLICK POINT IS IN THE SAME ROW AS THE BLANK PIECE
if (pieces[blankPiecePosition].sameRow(y)) {
if (pieces[click_piece].toLeft(pieces[blankPiecePosition])) {
cur = pieces[blankPiecePosition].left;
while (cur != pieces[click_piece].left) {
pieces[cur].exchangePiece(pieces[blankPiecePosition]);
blankPiecePosition = cur;
cur = pieces[blankPiecePosition].left;
congratulate();
}
} else if (pieces[click_piece].toRight(pieces[blankPiecePosition])) {
cur = pieces[blankPiecePosition].right;
while (cur != pieces[click_piece].right) {
pieces[cur].exchangePiece(pieces[blankPiecePosition]);
blankPiecePosition = cur;
cur = pieces[blankPiecePosition].right;
congratulate();
}
}
} else if (pieces[blankPiecePosition].sameColumn(x)) {
if (pieces[click_piece].above(pieces[blankPiecePosition])) {
cur = pieces[blankPiecePosition].up;
while (cur != pieces[click_piece].up) {
pieces[cur].exchangePiece(pieces[blankPiecePosition]);
blankPiecePosition = cur;
cur = pieces[blankPiecePosition].up;
congratulate();
}
} else if (pieces[click_piece].below(pieces[blankPiecePosition])) {
cur = pieces[blankPiecePosition].down;
while (cur != pieces[click_piece].down) {
pieces[cur].exchangePiece(pieces[blankPiecePosition]);
blankPiecePosition = cur;
cur = pieces[blankPiecePosition].down;
congratulate();
}
}
}
}
return true;
}
private void congratulate() {
if (simple.isPuzzleComplete()) {
graphics.drawString("Congratulations!!!", 75, 275);
}
}
public void paint(Graphics g) {
g.setColor(Color.pink);
g.fillRect(0, 0, size().width, size().height);
for (int i = 0; i <= (15); i++) {
pieces[i].draw();
}
}
// THIS ROUTINE RETURNS THE VALUE OF A LOCATION
public int getLocationValue(int arr_loc) {
return pieces[arr_loc].value.intValue();
}
// THIS ROUTINE RETURNS THE VALUE OF THE BLANK LOCATION
int getBlankLocationValue() {
return pieces[blankPiecePosition].value.intValue();
}
public boolean isPointInside(int x, int y) {
if ((x >= startX) && (y >= startY)
&& (x <= startX + rowSize * pieceWidth)
&& (y <= startY + rowSize * pieceWidth)) {
return true;
} else {
return false;
}
}
}
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
public class Piece {
int width = 50, height = 50;
int right, left, up, down;
Integer value; // the value of the Piece
Integer posX, posY; // the on screen position of the Piece
Graphics graphics;
Puzzle objPuzzle;
public Piece(int index, int val, Graphics agc, int x, int y, Image pict,
Puzzle objPuzzle) {
int temp;
this.objPuzzle = objPuzzle;
value = new Integer(val);
graphics = agc;
posX = new Integer(x);
posY = new Integer(y);
// RIGHT
temp = index + 1;
if ((temp == 4) || (temp == 8) || (temp == 12) || (temp == 16))
right = -1;
else
right = temp;
// LEFT
temp = index - 1;
if ((temp == 3) || (temp == 7) || (temp == 11))
left = -1;
else
left = temp;
// UP
temp = index - 4;
if ((temp < 0))
up = -1;
else
up = temp;
// DOWN
temp = index + 4;
if ((temp >= 16))
down = -1;
else
down = temp;
}
// RETURNS TRUE IF A POINT IS IN THE SAME COL AS y
public boolean sameColumn(int x) {
return ((x > posX.intValue()) && (x < posX.intValue() + height));
}
// RETURNS TRUE IF A POINT IS IN THE SAME ROW AS x
public boolean sameRow(int y) {
return ((y > posY.intValue()) && (y < posY.intValue() + width));
}
public boolean toLeft(Piece p) {
return (posX.intValue() < p.posX.intValue());
}
public boolean toRight(Piece p) {
return (posX.intValue() > p.posX.intValue());
}
public boolean above(Piece p) {
return (posY.intValue() < p.posY.intValue());
}
public boolean below(Piece p) {
return (posY.intValue() > p.posY.intValue());
}
public void exchangePiece(Piece blank) {
Integer temp = value;
value = blank.value;
blank.value = temp;
draw();
blank.draw();
}
public void draw() {
if (value.intValue() == 16) {
graphics.setColor(Color.black);
graphics.fillRect(posX.intValue(), posY.intValue(), width, height);
graphics.drawRect(posX.intValue(), posY.intValue(), width, height);
} else {
graphics.setColor(Color.yellow);
graphics.fillRect(posX.intValue(), posY.intValue(), width, height);
graphics.setColor(Color.black);
graphics.drawRect(posX.intValue(), posY.intValue(), width, height);
graphics.setFont(new Font("Times", Font.BOLD, 16));
graphics.drawString(value.toString(), posX.intValue()
+ (width - graphics.getFontMetrics().stringWidth(
value.toString())) / 2, posY.intValue() + height
/ 2);
}
}
}
public class SimplePuzzle{
int win[] = new int[16];
int winIndex, startIndex;
Puzzle puzzle;
SimplePuzzle(int startPosition, Puzzle puz) {
for (int i = 0; i < 16 ; i++) {
win[i] = i + 1;
}
winIndex = 15;
startIndex = startPosition;
puzzle = puz;
}
public boolean isPuzzleComplete() {
if (puzzle.getBlankLocationValue() != winIndex) {
return false;
}
for (int i = 0; i < 16 ; i++) {
//System.out.println("Loc Value: "+puzzle.getLocationValue(i)+"\tWin: "+win[i]);
if (puzzle.getLocationValue(i) != win[i]) {
return false;
}
}
return true;
}
}
/** **************************************************************** */
// THIS CLASS IS USED TO PROVIDE A UNIQUE RANDOM VALUE FROM
// A RANGE OF VALUES
class RandomValue {
int value[];
int total;
RandomValue(int first, int last) {
int i;
total = last - first + 1;
value = new int[total];
for (i = 0; i < total; i++) {
value[i] = first;
first++;
}
}
int getRandomValue() {
int i;
int ret;
if (total == 0) {
return -1;
}
if (total == 1) {
total = 0;
return value[0];
}
i = (int) (Math.random() * total);
ret = value[i];
total--;
for (; i < total; i++) {
value[i] = value[i + 1];
}
return ret;
}
}
|
|
|
|
|
this person is trolling. the entire text of this post (including the question) is copied from a two-year old posting on a java board.
|
|
|
|
|
|
I'm not trained in psychiatry
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
i have a problem with this tutorial in step3.
get_Sides and put_Sides methods not getting added! i dont't know y. plz check with below tutorial.
Tutorial[^]
|
|
|
|
|
1.Right-click IPolyCtl in Class View (expand the Polygon branch to find it).
If you Right-Clicked on _IPolyCtl then those methods won't be added. I think i had the same problem when using the tutorial.
|
|
|
|
|
Thanks for replying soon.
I am using VS2005. i have right clicked IPolyCtl and clicked Add property,but it doesn't add get and set method. But one thing i found that if we choose stock property in step 2 then this problem occures otherwise not.
|
|
|
|
|
Any solution to this problem?
|
|
|
|
|