I've not used C++ in a while, and I've become far too comfortable with the ease-of-use of real languages.
At any rate, I'm attempting to implement the Command pattern, and I need to map a number of command object implementations to string keys. I have an STL map of string to Command, and I'd like to copy the Command.
Essentially,
Com...
In my project several STL headers are used in different files. I read that, putting all these headers into a single header and using that header in my files will allow compilers to precompile the header which may lead into faster compile time.
If I understood it correctly, I need to write like the following.
// stl.hpp
#include <strin...
I'm having a significant problem using a standard BSD-style socket in a C++ program. In the code below, I connect to a local web server, send a request, and simply create a loop waiting for data to return. I actually do receive the data, but then I get an endless stream of 0-length data as if it was a non-blocking socket. The web server ...
I'm beginner to C++ and I wonder how to do this.
I want to write a code which take in a text line. E.g. "Hello stackoverflow is a really good site"
From the output I want only to print out the first three words and skip the rest.
Output I want: "Hello stackoverflow is"
If it was Java I would've used the string split(). As for C++ I d...
Hi,
i am experimenting with overloading the < operator (i'll add the > later) as a means for checking if one of the goldfish (please see code below) is within the territory of another (the territories can overlap). im getting multiple compile errors with teh code - primarily to do with being able to access the private variables, even ...
I am writing a program that will be used on a Solaris machine. I need a way of keeping track of how many seconds has passed since the start of the program. I'm talking very simple here. For example I would have an int seconds = 0; but how would I go about updating the seconds variable as each second passes?
It seems that some of the var...
Is there a linked list in C++ that I could just #include? Or do I need to create my own if I want to use one?
...
I have a question about the following code sample (taken from: http://www.albahari.com/threading/part4.aspx#_NonBlockingSynch)
class Foo
{
int _answer;
bool _complete;
void A()
{
_answer = 123;
Thread.MemoryBarrier(); // Barrier 1
_complete = true;
Thread.MemoryBarrier(); // Barrier 2
}
...
For some reason I can't get gdb to recognize the files in my project when debugging. I've tried a variety of things, including downloading different version, etc. and the last thing I did was completely overwrite all of MingW with Twilight Dragon Media's Bundle Package.
Does anyone know how to solve this issue? The odd thing was that wh...
I want to make win32 apps and games. Is there any major differences between C++ and Visual C++? What should I use.
...
This is for homework! But I need help anyway. The assignment is to input a sentence then output the number of words, and the number of occurrences of each letter. The output must have the letters in alphabetical order. So far, I've been able to count the number of words and get all the letters to lower case so that I'll be able to keep c...
Is there a way to choose the generic type of a class at runtime or is this a compile-time thing in C++?
What I want to do is something like this (pseudocode):
Generictype type;
if(somveval==1)
type = Integer;
if(someval==2)
type = String;
list<type> myList;
Is this possible in C++? and if yes, how?
...
I am writing a Matlab extension using the C++ ublas library, and I would like to be able to initialize my ublas vectors from the C arrays passed by the Matlab interpeter.
How can I initialize the ublas vector from a C array without (for the sake of efficiency) explicitly copying the data. I am looking for something along the following li...
I'm getting some errors when compiling my program. They relate to the constructor and destructor of my class Instruction.
Errors are:
/tmp/ccSWO7VW.o: In function `Instruction::Instruction(std::basic_string<char, std::char_traits<char>, std::allocator<char> >, int)':
ale.c:(.text+0x241): undefined reference to `vtable for Instruction'
...
My game uses a d = vt calculation for movement of objects where t is the time since the last frame (one frame per loop).
I'm using SDL and the gist of the timing calculation is that I create an instance of a Timer class and start it. I call GetSeconds() when it's needed which returns the difference between when the timer was started an...
I have a couple questions about how to use C++ sets (std::set)
Is there a way to get the union, intersection, or difference of two C++ sets? (It's pretty easy to write my own functionto do that but I wanted to know if there was a built in function for it)
Can C++ sets be used as keys in a map?
...
For a long time sending email uing SMTP (port 25) via a remote mail server (usually at the website hosting company) was easy to do with an application. Open a TCP port 25, send "HELO ..." etc
To do this using googles email service is giving me a problem because they insist on using port 465 SMTPS ie SMTP with TLS encryption:
http://en....
I have a function which returns the inner text of an xml element. It returns it, however, as a const wchar_t*. I wish to return this value as an integer (And a float in some other cases). What is the best method for doing so?
...
I'm trying to get a line as input from the command line. My problem is that I'm not getting the whole line, but it's being tokenized by space.
So if I entered something such as "I like Math a lot" instead of getting
"you enterend: I like Math a lot"
I get the follwoing:
EDITING MODE: Enter a command
i like Math a lot
you entered i
...
I was wondering if it is safe to do this...
delete p_pointer;
p_pointer = p_otherPointer;
Rather than...
delete p_pointer;
p_pointer = 0;
p_pointer = p_otherPointer;
I would assume so since there aren't any new memory allocations between the deletion and assignment, but I just want to make sure.
...