I'm looking for a string indexof function from the std namespace that returns an integer of a matching string similar to the java function of the same name. Something like:
std::string word = "bob";
int matchIndex = getAString().indexOf( word );
where getAString() is defined like this:
std::string getAString() { ... }
...
How can you put escape characters (like newline character -- \n) to a CString?
...
when they are represented in memory are objects C++ objects the same as C structs.
With C I could do something like this:
struct myObj {
int myInt;
char myVarChar;
};
int main() {
myObj * testObj = (myObj *) malloc(sizeof(int)+5);
testObj->myInt = 3;
strcpy((char*)&testObj->myVarChar, "test");
...
I want to supply a number, and then receive a set of random numbers. However, I want those numbers to be the same regardless of which computer I run it on (assuming I supply the same seed).
Basically my question is: in C++, if I make use of rand(), but supply srand() with a user-defined seed rather than the current time, will I be able...
I'm trying to use a typedef from a subclass in my project, I've isolated my problem in the example below.
Does anyone know where I'm going wrong?
template<typename Subclass>
class A {
public:
//Why doesn't it like this?
void action(typename Subclass::mytype var) {
(static_cast<Subclass*>(this))->do_action(var);
...
I have a data structure that looks like this:
typedef struct
{
unsigned short m_short1;
unsigned short m_short2;
unsigned char m_character;
} MyDataType;
I want to use boost::serialization to serialize this data structure, then use boost::asio to transmit it via TCP/IP, then have another application receive the data and de-seri...
I have an application where a bit of parallel processing would be of benefit. For the purposes of the discussion, let's say there is a directory with 10 text files in it, and I want to start a program, that forks off 10 processes, each taking one of the files, and uppercasing the contents of the file. I acknowledge that the parent progr...
Hello,
I'm trying to use Micosoft's SAL annotation for my project, however I get the following warning, and I don't know why.
As an example, I created a new C++ console application, and have this code:
#include <sal.h>
class Whatever
{
public:
_Check_return_ int Method(__in int number) ;
};
int main()
{
return 0;
}
When I ...
My code talks to a little Java application provided by a vendor. This Java app sets up a web server at localhost:57000 which is used to control the state of 'the machine'. For the purpose of this question, I need to change the state of 'the machine' from 'off' to 'on'. To make this happen I'm supposed to HTTP PUT the following string ...
I have created a very simple program that uses recursion. I'm using the g++ compiler. I can compile it, but when I try to run it I get an error message that says SEGMENTATION FAULT. Here's my code:
#include <iostream.h>
using namespace std;
int Recurse(int);
int main(int argc, char *argv[])
{
Recurse(10);
cout << endl;...
For a project of mine, I am writing some STL containers from scratch (I have my reasons). Since I am mimicking the functionality and interfaces of the STL so closely I am doing my best to keep with the policy "if it has the same name as a standard construct, it will conform to the standard as much as possible."
So, of course my containe...
I am using a library that consists almost entirely of templated classes and functions in header files, like this:
// foo.h
template<class T>
class Foo {
Foo(){}
void computeXYZ() { /* heavy code */ }
};
template<class T>
void processFoo(const Foo<T>& foo) { /* more heavy code */ }
Now this is bad because compile times are unbearab...
What is the worst real-world macros/pre-processor abuse you've ever come across (please no contrived IOCCC answers *haha*)?
Please add a short snippet or story if it is really entertaining. The goal is to teach something instead of always telling people "never use macros".
p.s.: I've used macros before... but usually I get rid of the...
I'm trying to get a better understanding of what place (if any) Macros have in modern C++ and Visual C++, also with reference to Windows programming libraries: What problem (if any) do Macros solve in these situations that cannot be solved without using them?
I remember reading about Google Chrome's use of WTL for Macros (amonst other t...
The title pretty much says it all.
The __COUNTER__ symbol is provided by VC++ and GCC, and gives an increasing non-negative integral value each time it is used.
I'm interested to learn whether anyone's ever used it, and whether it's something that would be worth standardising?
...
Description of Scenario for project: To search and articles in a library computer system one uses keywords in combination with Boolean operators such as 'and'(&) and 'or(). For example, if you are going to search for articles and books dealin with uses of nanotechnology and bridge construction, the query would be Nanotechnology & bridge ...
Is this guaranteed to be always true:
std::numeric_limits<int>::max() == INT_MAX
What does C++ standard say about it? I could not find any reference in the standard that would explicitly state this, but I keep reading that those should be equivalent.
What about C99 types that are not in C++98 standard for compilers that implement bot...
I have a dll which comes from a third party, which was written in C++.
Here is some information that comes from the dll documentation:
//start documentation
RECO_DATA{
wchar_t Surname[200];
wchar_t Firstname[200];
}
Description:
Data structure for receiving the function result. All function result will be
stored as Unicode (UTF-8).
...
This should be trivial but I can't seem to find it (unless no such class exists!)
What's the STL class (or set of classes) for smart pointers?
UPDATE
Thanks for the responses,
I must say I'm surprised there's no standard implementation.
I ended up using this one: http://www.gamedev.net/reference/articles/article1060.asp
...
Should a buffer of bytes be signed char or unsigned char or simply a char buffer?
Any differences between C and C++?
Thanks.
...