question_id
int64
25
74.7M
answer_id
int64
332
74.7M
title
stringlengths
20
150
question
stringlengths
23
4.1k
answer
stringlengths
20
4.1k
5,344,049
5,344,107
C++: How do I store a 256 bit number, and how do I convert it to hex?
ints only go to 32 bits, longs to 64bits... so.. what do you do when you are working with a much larger number? Also, how easy would it be to switch between the binary representation and the hex representation?
ints only go to 32 bits, longs to 64bits... so.. what do you do when you are working with a much larger number? You use large number libraries. Also, how easy would it be to switch between the binary representation and the hex representation? I don't understand the question. A number's a number's a number. Are yo...
5,344,110
5,344,207
How to write signatures database for AntiVirus?
i wrote small code in C to scan all files & folders in my hard drive... and it also can read the upper part of the binary code of executable files (like .exe ) and compare it with an inline single binary signature (in hexadecimal representation) . It can show a message if the signature matches the bin code of any scan...
Berkeley DB is a free/open source embedded database library that is basically a key-value store on disk (search tree or hash table, depending on settings). It's even simpler than SQLite because it avoids the idea of relational data and SQL. You could use virus signatures as keys and their names as values, for example.
5,344,136
5,357,741
E_ACCESSDENIED on CoCreateInstance, where it used to work
I have some code that used to work, but recently stopped. It's in an Adobe Reader Plugin, and the latest Reader version has a "Protected Mode" which causes my problem. My plugin can load some of my normal dlls, which load in-process: MyNormalLib::IMyClassPtr foo; HRESULT hr = foo.CreateInstance(__uuidof(MyNormalLib::M...
The restricted process does not have admin rights. That's pretty much the point of the exercise - Reader X drops as many rights as it can from its token so that if it is pwned your computer is not. (That's basically how UAC works too, you have to go to the Kernel to get permission to re-enable your Administrator group ...
5,344,219
5,344,238
function gives wrong results
I have tried writting the following function to generate all combinations of a string by translating the algorithm from my algorithm text. But it keeps print entire string in the output for all the combinations. len = strlen(str); for(i=0;i<pow(2,len);i++) { for(j=0;j<len;j++) { if(i ...
Since you want to check if the jth bit is set in variable i you need to use the bitwise & operator and not the logical &&: if(i && (0x1 << j)) ^^
5,344,387
5,344,449
assigning binary to vector C++
I am trying to convert a number to network and then to put the result in a vector in std::vector<char> vctData; u_long lnum = 145; lnum = htonl(lnum); //This line should put lnum at the beginning of vector in the first 4 bytes vctData.insert(vctData.begin(), ???, ???); what to do ??? Thanks
std::vector<unsigned char> vctData; u_long lnum = 145; lnum = htonl(lnum); vctData.insert(vctData.begin(), (unsigned char *) &lnum, (unsigned char *) (&lnum + 1)); This takes the individual bytes of lnum and puts them one by one into vctData.
5,344,399
5,344,452
Sending data to web through command-line with javascript built-in
Webkit and Selenium use a browser interface to interact with javascript elements and send data. Is there a way where I can fill in a ajax form and send data straight from a command-line ? If not, why is it not possible ? If so, how ? Thanks
You can use my terminal emulator jquery plugin, but If you want to do AJAX when you don't have access to javascript source code you will need to create Bookmarklet
5,344,809
5,345,349
Boost.Asio async_send question
I'm using Boost.Asio for a server application that I'm writing. async_send requires the caller to keep ownership of the data that is being sent until the data is sent successfully. That means my code (which looks like the following) will fail, and it does, because data will no longer be a valid object. void func() { ...
A possible fix would be to use a shared_ptr to hold your local vector and change the handler's signature to receive a shared_ptr so to prolong the life of the data until the sending is complete (thanks to Tim for pointing that out to me): void handler( boost::shared_ptr<std::vector<char> > data ) { } void func() { ...
5,345,058
5,345,138
Interview: what is the difference between pthread and windows thread created by _beginthread(ex)?
I was asked about this in an c++ developer position interview, what is the answer to this?
I would have said: If I wanted to create a portable cross-platform C++ binary, I'd use pthreads and use the pthread implementation for windows. If I wanted to create a windows-specific C++ binary, I'd use beginthread and avoid the 3rd party dependency on the pthread library. If they really wanted to kno...
5,345,110
5,364,067
Using ODBC to connect to SQL SERVER 2008
I'm on a W32 machine trying to get a connection with a DB. For that purpose, I tried starting testing an example program: #include <iostream> #include <windows.h> #include <sqltypes.h> #include <sql.h> #include <sqlext.h> using namespace std; void show_error(unsigned int handletype, const SQLHANDLE& handle){ SQLC...
I have found with stdafx.h header that the include order should be instead: #include <iostream> #include <windows.h> #include <sqlext.h> #include <sqltypes.h> #include <sql.h>
5,345,152
5,345,218
Why would I prefer using vector to deque
Since they are both contiguous memory containers; feature wise, deque has almost everything vector has but more, since it is more efficient to insert in the front. Why whould anyone prefer std::vector to std::deque?
Elements in a deque are not contiguous in memory; vector elements are guaranteed to be. So if you need to interact with a plain C library that needs contiguous arrays, or if you care (a lot) about spatial locality, then you might prefer vector. In addition, since there is some extra bookkeeping, other ops are probably ...
5,345,527
5,345,556
What does the "::" mean in C++?
What does this symbol mean? AirlineTicket::AirlineTicket()
:: is the scope resolution operator - used to qualify names. In this case it is used to separate the class AirlineTicket from the constructor AirlineTicket(), forming the qualified name AirlineTicket::AirlineTicket() You use this whenever you need to be explicit with regards to what you're referring to. Some samples: n...
5,345,682
5,345,879
c++ crashing on incrementing an unsigned long int
This one is WTF city. The below program is crashing after a few thousand loops. unsigned long int nTurn = 1; bool quit = false; int main(){ while(!quit){ doTurn(); ++nTurn; } } That's, of course, simplified from my game, but nTurn is at the moment used nowhere but the incrementing of it, and w...
Your problem is elsewhere. Some other part of the program is reading from a wild pointer that ends up pointing to nTurn, and when this loop changes the value the other code acts different. Or there's a race condition, and the increment makes this loop take just a tiny bit longer so the race-y thing doesn't cause troub...
5,345,803
5,346,026
Does GDI+ have standard image encoder CLSIDs?
The GDI+ Image::Save method requires a CLSID parameter to specify the encoder to use. The documentation points to some sample code for getting the encoder associated with a particular MIME type, such as image/jpeg or image/png. However I'm balking at the thought of copying a half-page function just to support a 1-line ...
There isn't one. I think they intended the codec list to be extensible and support plugins, but never got around to it. Given that they haven't made any changes to GDI+ in quite some time, they likely won't anytime soon. You could probably get away with generating your own hard coded list based on an enumeration of G...
5,345,807
5,345,851
Trouble with infinite recursion in function
I've been working since yesterday to get this function working, but its just not. I've tried everything. I'm using a function that has depth recursion. The output I get is very strange: Im going in with depth: 8 Depth in builder: 8 Depth in builder: 7 Depth in builder: 6 Depth in builder: 5 Depth in builder: 4 Depth i...
I'm not sure that it actually displays them forever; it might just go on for a while. Your recursive function makes four recursive calls at each level and runs from depth 8 to depth 0. This means that there are a total of 48 = 65536 recursive calls at the bottom, 47 = 16384 calls at depth 1, etc. for a total of 87381 ...
5,346,160
5,346,563
llvm IRBuilder<>::CreateUDiv/CreateSDiv/CreateExactUDiv
I've seen that to create division operations there is variety of possibilities, UDiv/SDiv and ExactUDiv, i infer that the difference between U and S stand for Unsigned and Signed, but that means that the sign is ignored for Unsigned? also, what means Exact? that the result is a float? Also, what does mean NSWAdd and NU...
I assume LLVM uses two's complement to store integers and in that case a (signed) negative number will seem like a large unsigned number for UDiv, (e.g. the two's complement representation for 32-bit -1 is 0xFFFFFFFF). Thus SDiv(-16, 2) == -8 while UDiv(-16, 2) == 2147483640. So in short: no, the sign is not just ignor...
5,346,331
5,346,351
how does the server know that the client is still connected?
a client establishes a connection to a server process. how does the server knows that the client is still connected? For example the server is a web server and a client is a browser. Let's assume that the requirement is that the server should always wants to know that the client is connected. How is that implemented/d...
HTTP Sessions can help.
5,346,389
5,346,417
Why operator [] is not allowed on std::auto_ptr
Why operator [] is not allowed on std::auto_ptr? #include <iostream> using namespace std ; template <typename T> void foo( T capacity ) { auto_ptr<T> temp = new T[capacity]; for( size_t i=0; i<capacity; ++i ) temp[i] = i; // Error } int main() { foo<int>(5); return 0; } Compiled on Microsof...
The reason is that auto_ptr will free the content using delete instead of delete[], and so auto_ptr is not suitable for handling heap-allocated arrays (constructed with new[]) and is only suitable for handling single, heap-allocated arrays that were constructed with new. Supporting operator[] would encourage developers...
5,346,445
5,346,501
How to synchronize input with output on a terminal?
I'm writing a linux shell for a custom scripting language, and I want to print a "... " before each follow-up line a user enters for a single statement, with the first line having a ">>> " printed, then waiting for input. Following is an example: >>> void f() { ... "this is a test" ... } >>> I'm reading the line wit...
If you turn off echo (see stty(1) -echo) for the terminal, then you are in complete control over when the input is printed to the screen. My assumption is the paste is causing all lines to be written to the terminal at once, and your program will never get an opportunity to send output to the terminal when necessary. S...
5,346,695
5,346,724
c++ const use in class methods
Possible Duplicates: What's the use of const here Using 'const' in class's functions Hi All, I keep making mistakes about the use of const with class methods and variables. For example, sometimes I fix problems using const int myfunc(const int &obj) const { } some other times I feel I don't need const at the end si...
const int myfunc(const int &obj) const { } The first const indicates that the return value is constant. In this particular case, it's not particularly relevant since the int is a value as opposed to a reference. The second const indicates the parameter obj is constant. This indicates to the caller that the parameter...
5,346,774
5,346,792
Why does this code say I need a class/struct/union?
I've been programming in java and AS3 and C# for some time, and decided to give C++ a try... So, I decided to create a simple program to see how objects work here. I have two files: Human.h #pragma once #include <string> #include <iostream> using namespace std; class Human { private: int _age; stri...
You have declared me as a pointer. Either remove the * on the declaration, or Use me->GetName() etc to use it. = = = edit = = = Since there is no default constructor, the * must remain. Either that or change it to Human me(27, "name", true);
5,346,836
5,346,875
C++11 - Distinguishing rvalue pointers
How can I distinguish a variable as a compiler-constructed string? For example, while the rvalue "Hello, World" is of type const char*. const char* in itself does not mean that a pointer can't be changed. A char* const pointer can't be changed, but that's not what's constructed by the compiler. Does this mean that, fo...
"Hello, World" is not of type const char*. It is of type const char[13] and it is an lvalue, not an rvalue. When you use "Hello, World" in a context in which it is implicitly converted to a const char* pointing to its initial element, the resulting pointer is an rvalue (because it is a temporary object resulting from ...
5,346,853
5,346,866
C++: Why pass-by-value is generally more efficient than pass-by-reference for built-in (i.e., C-like) types
just as what indicated in the title
A compiler vendor would typically implement a reference as a pointer. Pointers tend to be the same size as or larger than many of the built-in types. For these built-in types the same amount of data would be passed whether you passed by value or by reference. In the function, in order to get the actual data, you would ...
5,346,890
5,346,927
what is the difference between const_iterator and iterator?
What is difference between these two regarding implementation inside STL. what is the difference regarding performance? I guess when we are traversing the vector in "read only wise", we prefer const_iterator, right? Thank you.
There is no performance difference. A const_iterator is an iterator that points to const value (like a const T* pointer); dereferencing it returns a reference to a constant value (const T&) and prevents modification of the referenced value: it enforces const-correctness. When you have a const reference to the container...
5,346,897
5,346,929
A Recursion function in C++
If I have this recursive function: int mystery(int n) { if ( n == 0 || n == 1 || n == 2) return n ; return (mystery(n-1) + mystery(n-2) + mystery(n-3)) ; } I am working with finding mystery(20). How can I find out how many addition operations are carried out when calculating the function and how many invocations...
The easiest way to do is to increment a global (or static global) variable. Something like to get the number of mystery call: int nb_of_invok = 0; int mystery(int n) { nb_of_invok++; ...your code here... } And this to get the number of additions: int nb_of_invok = 0; int nb_of_add = 0; int mystery(int n) { nb_of...
5,347,042
5,347,066
Are "char" and "small int" slower than "int"?
Possible Duplicate: Performance of built-in types : char vs short vs int vs. float vs. double Hi. Assume, that you have 32-bit processor. Are 8-bit char and 16-bit short int types slower than native 32-bit int? What about using 64-bit long long int? Are this datatypes supported by hardware by default, or they are al...
On any modern, practical machine, char, int, and long will all be fast (probably equally fast). Whether short is fast or not varies somewhat between cpu architecture and even different cpu models within a single architecture. With that said, there's really no good reason to use small types for single variables, regardl...
5,347,134
5,347,214
C++ iterator question
I saw an interview question, which was asked to use "iterator" to read vector<vector<int>>. We have to design the necessary interface? Quite confusing about does this question want to ask? Or how to answer this kind of question. I can imagine that it intends to test C++ STL implementation and objected-oriented design.
Matrix is in 3*4 dimension. If needed to access only through iterators, this should give you an idea - vector< vector<int> > Matrix(3, vector<int>(3,4)); for( vector<vector<int>>::iterator i = Matrix.begin(); i != Matrix.end(); ++i ) { for( vector<int>::iterator j = (*i).begin(); j != (*i).end(); ++j ) { ...
5,347,392
5,347,450
dynamically allocate array of structs with C++
My problem is that I have a class, which should take a long int called "size", and use it to dynamically create an array of structs. The following compiles, but I get a runtime error that says the following: error "terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc Aborted struc...
My guess is that when you call the function size somehow ends up being some ridiculously huge number or negative. Try printing it out inside the function and telling us what it is. You're probably running out of memory. Also, stop using endl unless you mean it specifically instead of '\n'.
5,347,395
5,347,625
boost python question
I'm trying to expose one of my classes to python using boost's python module. I have a class called StatusEffect that I'd like to expose to python. To do so, I'm creating this in the StatusEffect.h file after the class definition of StatusEffect BOOST_PYTHON_MODULE(StatusEffect) { boost::python::class_<StatusEffect...
One thing to note is that your wrapper should be in your StatusEffect.cpp, not StatusEffect.h or a separate CPP file. However, it should be OK anyway, since everything should still get exported. I would also write a test script in Python, instead of trying to test it from C. There is not enough information to figure ...
5,347,420
5,347,570
Binary image code size comparison between Cocoa Touch Static Library and DLL dynamic library
I am migrating a C++ dynamic DLL library from Windows OS to iOS with static library(.a). And some issues come up about the binary image size. Here are some data I got. Image size: dynamic library (DLL compiled in Windows OS) : 1.4M static library(.a,complied with Touch Static Library): 34M. I checked each complied C...
In Unix-based systems (including iOS), a ".a" file is simply an archive (man 5 ar) combining a bunch of ".o" files in a single unit (possibly with the inclusion of a symbol table). So, your observation the size of the ".a" file is the summation of the ".o" files is exactly correct. When you link an application against ...
5,347,441
5,347,460
Need help on Dissection C++ number 2 sting function
I found a bug on the function below. When temp = 10. It will convert temp to string '01'. instead of string'10'. I can't tell why? Is there any better to convert Num to Str? Thanks. completed Num2Str() as this, static bool Num2Str(string& s, const T& value) { int temp = static_cast<int>(value); // When temp = 10. ...
Use std::ostringstream to convert numbers to strings. Don't use free static functions in C++; use unnamed namespaces instead. #include<sstream> #include<string> namespace { void f() { int value = 42; std::ostringstream ss; if( ss << value ) { std::string s = ss.str(); } else { // failure ...
5,347,444
5,352,236
Overload resolution and arrays: which function should be called?
Consider the following program: #include <cstddef> #include <cstdio> void f(char const*&&) { std::puts("char const*&&"); } // (1) void f(char const* const&) { std::puts("char const* const&"); } // (2) template <std::size_t N> void f(char const (&)[N]) { std::puts("char const(&)[N]"); } // (3) int main()...
First, the conversion sequence of all three is the same, except that for the first two, there is an lvalue transformation (lvalue to rvalue conversion), which however is not used in ordering conversion sequences. All three are exact matches (the function template specialization has parameter type char const(&)[2]). If...
5,347,614
5,347,707
C++ Copy Constructor invocation
Quick question. If I have an array and have properly overloaded the assignment operator, then when I do something like this: A = B When A and B are both objects of type array, am I calling the copy constructor, or just the overloaded assignment operator(=)? I know that a copy constructor is called when Pass By val...
Since you've said the array is your own class with an overloaded assignment operator then you've already answered your own question. The copy constructor is literally only called when you are constructing the object from another: Obj a; Obj b(a); It might wind up being called by some sort of compiler magic if you do: O...
5,347,618
5,347,785
How to validate hex input with std::cin?
I did the following method as in http://www.parashift.com/c++-faq-lite/input-output.html to validate, but it does not work: if (!(cin >> hex >>address1)) { cout << "Invalid input."; std::cin.clear(); std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); } ...
I guess I'd do something like this: std::getline(cin, your_string); if (your_string.find_first_not_of("0123456789abcdefABCDEF") != std::string::npos) error("Non-hexadecimal input"); else { std::istringstream is(your_string); is >> std::hex >> address1; } There are a lot of variations, but the three steps ...
5,347,725
5,347,856
Cant seem to find reason for infinite loop
Im writing a program that will help sort out classes for a 4 year college. for some reason, im getting stuck in the while loop. /* some info: "course" is a class i created some of the member function are: bool fall() // does the class run in the fall? bool spring() // does the class ru...
What do you think this does? if ((x == classes.size())) x %= classes.size(); The assignment is the same as: x = x % classes.size(); But you just found out x == classes.size() so x = classes.size() % classes.size(); And for any N, N%N is zero, so that means if ((x == classes.size())) x = 0; Is that wha...
5,347,744
5,347,781
why put a "const" at the end?
Possible Duplicates: c++ const use in class methods Meaning of “const” last in a C++ method declaration? int operator==(const AAA &rhs) const; This is a operator overloading declaration. Why put const at the end? Thanks
The const keyword signifies that the method isn't going to change the object. Since operator== is for comparison, nothing needs to be changed. Therefore, it is const. It has to be omitted for methods like operator= that DO modify the object. It lets the compiler double-check your work to make sure you're not doing a...
5,347,867
5,348,032
Color detection algorithm - How should I do this?
I'm a bit stuck on designing a color detection system - I can't quite figure out a way to do it easily. - Basically, I have a library of images, that I want to sort by color. So if the user specifies 'sort by blue', then the most blue images will appear at the top of the results, with the least blue appearing at the bo...
Two thoughts come to mind: Cheap version: convert images to HSV color space, and for each pixel compute cos(H - target_hue) or a reasonable approximation (for blue, target_hue would be 240 degrees), multiply by saturation, and average that quantity over all of the pixels in the image. High values are best. Note that co...
5,348,077
5,348,114
C++ macro problem (interpretation of comma ,)
The following code compiles fine. #define CMD_MACRO(pp, cmd) \ { \ if (pp)\ { cmd; } \ } template<class T> void operate_on(T &data, char c) { data=data+1; }; int main() { int book=4; char c; CMD_MACRO(book, { operate_on<int>(book, c); }); }; Note that the actual ma...
Have you tried: (operate_on<int, false>(book, c));? (Notice the extra parentheses around the expression). I believe the preprocessor knows nothing of C++ templates, and so treats the < and > as just any old token. Without the extra parentheses, it treats operate_on<int as one argument, and false>(book, c) as anothe...
5,348,334
5,352,065
How do I communicate between C++ and Flash?
Is there any way I can have an integration between Flash AS and C++? Let's say I have created a socket using C++ and multi-casting it to several ip addresses. On one of the IPs I am running a Flash client. Can I receive the Multicast message (sent by MFC/C++ application) through my Flash application. Or at least can I ...
Depends on what you would like to do. If you host the swf's in your application you can use the ExtenalInterface in flash via the ActiveX container. http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.html We are using that method in our project, check it out (open source): http:/...
5,348,344
5,348,475
HTTP Client library for C++
I'm trying to write milt-threaded HTTP proxy for learning C++/socket/HTTP I'm looking for a HTTP client library like HttpURLConnection available in Java. I looked at some libraries eg, libcurl for C/C++. These libraries can make http request but they will return with the full content. I need a library that can read co...
libcurl docs have an example page on how to get incremental download callbacks (into a memory buffer) as data streams in from a request: http://curl.haxx.se/libcurl/c/getinmemory.html In your case, you would just forward the data buffer on to the client that originally made the request.
5,348,536
5,348,549
Vector pointer and push_back()
If I have void f(vector<object> *vo) { } And I pass the address of a vector to f vector<object> vo; f(&vo); How would I use push_back() to add to the vector?
Dereference the pointer: (*vo).push_back(object()); vo->push_back(object()); // short-hand Note this is a basic concept of the language, you may benefit from reading a good book. Note this has a glaring shortcoming: f(0); // oops, dereferenced null; undefined behavior (crash) To make your function safe, you need to ...
5,348,537
5,349,827
Creating .sln/vcproj files
I would like to write a program or script that would generate .vcproj and .sln files for me. I currently have a lot of settings/configurations that I need to set for every .vcproj I create and I have seen people be able to generate these files some how, although I can not find a good resource through msdn or bing to do...
You can generate .sln/.vcproj with MSVS object model. It can be macros or add-in. This sample is a macros to generate .sln/.vcproj. Sub SlnVcprojGenerator() Dim sln As Solution Dim prj As Project sln = DTE.Solution sln.Create("C:\test", "new_sln.sln") prj = sln.AddFromTemplate("C:\Program Files (x86...
5,348,765
5,348,788
why compiler gives undefined reference
I have this code: in header file class SocialNet { private: // some data public: // some other operations template <typename T, typename V> T find(V identifier, const vector<T>& objects) const; }; in .cpp file // in that file, I ...
You can not implement a template in a .cpp file, the function definition of find should be there in the header file. See this FAQ Why can't I separate the definition of my templates class from its declaration and put it inside a .cpp file? for more details.
5,348,908
5,348,983
How to use _beginthreadex in MFC
I want to create a worker thread using _beginthreadex(). However, the compiler says: Error 1 error C2276: '&' : illegal operation on bound member function expression Here is my code: .cpp file hThread = (HANDLE)_beginthreadex( NULL, 0, &Udp_Thread, NULL, 0, &threadID ); // Function caller in main() unsigned __std...
C2276: The compiler found a problem with the syntax to create a pointer-to-member. You need to specify the class scope. Further _beginthreadex takes a function pointer not a member function pointer. So you must pass the address of a static function. Use this one: classs CUdpSocket { public: unsigned static __std...
5,348,947
5,348,973
calling legacy function with shared pointer
i am trying to call a legacy function, which takes normal pointer parameter, with a shared pointer and i am getting the following error: I have tried to convey the idea, by a simple example, what i am doing. I cannot change the parameter to display(), as it is in legacy and is being used by many other modules..But from...
Does the function attempt to free the pointer? If not, the best thing to do is to use shared_ptr's get() method, like so: display(ptr.get());
5,349,214
5,349,319
C++ function pointers inside templates
I have this problem: template<typename T> class Bubu { ... int (*comparer)(const T t1, const T t2); ... public: Bubu(int (*_comparer)(const T t1, const T t2)) { comparer = _comparer; } }; And in another file: Bubu<char*> asd(strcmp); Error: error C2664: 'Bubu<T>::Bubu(int (__cdecl *)(const T,const...
When T is char*, const T is char* const which isn't the same thing as const char *. You need: Bubu<const char*> asd(strcmp); Top level const is ignored for function signatures so int (*)( const char* const, const char* const ); is the same type as int (*)( const char*, const char* ); so you're OK on the extra top l...
5,349,562
5,349,597
understanding c++, compilation etc
Do you know a good, concise (not a book, possibly free documentation) reference that explains the basics of how a c++ compiler works? I think it'd be beneficial for better understanding some rules of c++ programming.
GCC Internals free ebook. The purpose of this book is to address the demands of GCC hackers. We start with a description of GCC 3.4.1 architecture focusing on the source code parser. We chose this version of GCC because we used this version mostly. Then we address the problem of extension development. We...
5,349,599
5,349,625
pointer segfault problems
pointer segfault problems... I've been doing c++ for some weeks meanwhile but i ran again into that issue. basically i have these classes given. I cant change them. I start with an instance of _ns3__importAuftragResponse kout; class SOAP_CMAC _ns3__importAuftragResponse { public: ns2__SOAPImportResult *return_;...
Most likely you've not allocated memory for the following members which you're using in the code you've quoted. ns2__SOAPImportResult *return_; //in the class _ns3__importAuftragResponse int *numberOfIgnoreds; //in the class ns2__SOAPImportResult Other than this I don't see anything where things might go wrong! M...
5,349,723
5,349,744
Overloading global new and delete safely
While reading Bruce Eckel i came across the following example: #include <cstdio> #include <cstdlib> using namespace std; void* operator new(size_t sz) { printf("operator new: %d Bytes\n", sz); void* m = malloc(sz); if(!m) puts("out of memory"); return m; } void operator delete(void* m) { puts("operator del...
Use of printf() to avoid a recursive call into operator new() is a safety measure - just to be sure it works. How do you know use of iostream never ever causes a call to operator new() function? You're confusing new expression (a language construct) with operator new() function. new expression indeed returns a typed p...
5,349,777
5,349,840
TestPlugInRunnerd.exe + gmock
We build our cppunit unittests as a dll and load it into TestPlugInRunnerd.exe to show our results. We write our own mocks but I'd like to start using a mocking framework such as gmock. I downloaded gmock and linked against it without much in the way of problems. I have written a mock using gmock and it compiles fine....
First, it is not possible that you don't have a main. Otherwise how would you execute your unit tests? Second, you could create a static variable of a class where you call these two functions, like this : struct GmockInitializer { GmockInitializer() { ::testing::GTEST_FLAG(throw_on_failure) = true; ::testin...
5,349,812
5,351,137
Could C++ or C99 theoretically be compiled to equally-portable C90?
This is a big question, so let me get a few things out of the way: Let's ignore the fact that some C++ features cannot be implemented in C (for example, supporting pre-main initialization for any global static object that is linked in). This is a thought experiment about what is theoretically possible. Please do not ...
It is not only theoretically possible, but also practically trivial - use LLVM with a cbe target.
5,349,845
5,349,892
Linux, C++, will dup(socket) work from another not forked process (if not how to enable it)?
So I opened a socket connection like was described here I want to let other processes use that open connection. Will dup() help me or what shall I do?
In order to pass sockets between existing processes you need to use sendmsg - Or libancillary which abstracts the whole thing.
5,349,973
5,350,176
why did it compile errorly when i added a reference argument to a member function which is the argument to std::mem_fun()?
Firstly, I had a snippet as following: struct D { int sum; D():sum(0){accum();} void incre(int arg){sum+=arg;} void accum() { int arr[]={1,2,3,4,5}; std::for_each(arr,arr+ sizeof(arr)/sizeof(int), std::bind1st(std::mem_fun(&D::incre),this)); cout << sum <<endl; } }; int ...
The problem is that internally, mem_fun tries to set as its argument type a const reference to the argument type of the member function. If you make then function take in a reference, then it tries to create a reference to a reference, which is illegal in C++. This is a known defect in the library and is being remedi...
5,350,037
5,350,250
Don't open console output with system()
Possible Duplicate: Hide console in C system() function, Win. Hi guys I have a little problem, I need to ping a lot of PC, so in my program i call the function system() with "ping -n 1 > tmp.txt", but I don't want that the console window is shown. How can I do it? P.S.: I use dev c++ :D thx
I found what you might be looking for here Hide a window in C++ And also here I guess the freeconsole() method is what you are needing?
5,350,049
5,351,411
What's the difference in c++ between new int and new (int)?
what's the difference between int * num = new (int); and int * num = new int; ? Is there a difference at all? EDIT thx all. ... which one is the most correct answer?
There isn't a difference in the context of your example (using an int type). However, there is a difference if you need to create objects of compound types, where you need to use parenthesized version. i.e: int (**fn_ptr_ok) () = new (int (*[10]) ()); // OK int (**fn_ptr_err) () = new int (*[10]) (); // error
5,350,072
5,351,240
Read Bmp Greyscales into C
I looked for how to read a Bmp file into a 2 or 1 dimensional Array under C , there are many solutions but not the one i need. I need to read the Black and white bmp into (to beginn) 2 dimensional array which have to contain values from 0 to 255 (greyscale) and then transform it to 1 dimensional array(but that's not a ...
There's a bmp loader which I made for another SO question: http://nishi.dreamhosters.com/u/so_bmp_v0.zip The example bmp there is RGB, but it seems to work with grayscale as well. FILE* f = fopen( "winnt.bmp", "rb" ); if( f==0 ) return 1; fread( buf, 1,sizeof(buf), f ); fclose(f); BITMAPFILEHEADER& bfh = (BITMAPFILEH...
5,350,125
5,350,155
Constructor of type int
Considering the cost, are these cases the same? // case 1 int a = 5; // case 2 int a (5); // case 3 int a; a = 5
First and second are exactly same as both are initialization. Third one is different, as this is assignment. These differences are as per the C++ Standard. However, the compiler can treat all three as same!
5,350,549
5,350,707
Checking heap integrity when _DEBUG is not defined?
I wish to create a build of a project constructed so that it is identical to the release build, except that the debug version of the default allocator is used (with canary checks on alloc/free and so on). The compiler/CRT is Visual Studio 2010. Reading the documentation for the CRT it seems that _DEBUG needs to be defi...
_malloc_dbg() requires the debug runtime, the debug runtime requires _DEBUG - So no, you can't do this.
5,350,591
5,350,641
Problem with declaring Objects in C++
I have a simple code below: class B; class A{ B b; }; class B{ public: B(){ } }; In class A's definition, I have a B-typed property. Using MS Visual Studio to compile, I've got the following error: error C2079: 'A::b' uses undefined class 'B' Due to some reasons, I can't put class B's definition before ...
The compiler is already telling you what's wrong : A has a member data b which is of an undefined type. Your forward declaration: class B; is just that : a declaration, not a definition. Since class A contains an instance of B directly (not just a pointer to B), the compiler needs to know the exact size of B : it need...
5,350,651
5,352,544
COM ATL Threading Model or not
i am a little confused about COM threading models. I got a C++ COM DLL. It is defined as single apartment model: _ATL_APARTMENT_THREADED My test app is written in C# and does the following: start thread 1 thread 1:setName start thread 2 thread 2:setName since my dll is ATL I would expect the name attribute in the DLL...
You don't ever instantiate a COM object in your code. You instantiate a COM object using new on a type from an interop assembly (the one you get when you add a reference to a COM library) which calls CoCreateInstance() WinAPI function under the hood. No call to CoCreateInstance() - no threading models, so no restrictio...
5,350,712
5,351,401
How to get the boost::asio::async_read to return when the terminating character is reached
i'm using boost asio library to read the content from the tcp socket. My code looks like this std::string completeBuffer=""; std::string TcpConnection::readMessage() { LOG4CPLUS_DEBUG(logger, "Start Listener for Reading Message from Connection"); boost::system::error_code error; boost::asio::async_read(sock...
Found the answer async_read_until
5,350,740
5,358,077
C++ 2D Graphics Library that handles 1,000,000 2D sprites?
I'm trying to do a project that need to handles very large amount of simple 2D objects, and of course needs to draw them. For that, I need a good C++ library that can handle large amount of "sprites". I've been trying Qt, because I thought their "40,000 chip" demo was very impressive. However, with a bit of toying, it ...
To my knowledge no mainstream videogame exists that renders 1,000,000 2D sprites (particles) in one frame. A research project from 2004 showed how it could be done, however: Building a Million Particle System In my opinion, when videogames finally do render 1,000,000 particles in a frame, they will do so via OpenCL or...
5,351,316
5,365,816
qi::rule<It, std::string ()> doesn't parse input string
I have a strange trouble: qi::rule <Iterator, std::string ()> str = +alnum; // will not parse given input //param = "WELL" >> space >> str >> ((space >> no_case[control]) || (space >> no_case[limit])) >> space >> qi::eol; // will parse given input ok param = "WELL" >> space >> +alnum >> ((space >> no_case[control]) |...
The problem is that you defined the rule str on the stack (as a local variable inside the constructor). This variable goes out of scope when the constructor of your grammar is exited, leaving the param rule with a dangling reference to it. If you move str to be a member variable of the grammar everything works as expec...
5,351,553
5,351,616
Improvement on flag files and data files?
I have a existing project (non-web), with multiple components/programs running on different machines. The programs use flag files e.g. "xxx.request" "xxx.done" to signal each other. And also data files are created and put in a particular directory and passed to another program to process. The data files and flag files ...
I suggest you use a messaging system for sending messages. Files don't make a good reliable, secure, mangageable, or fast protocol for sending data between applications. In Java I would use JMS which has many implementations which have C# and C++ clients.
5,351,757
5,351,784
Linking fails when missing implementation of a not-used pure virtual method
I have a class, which inherits from a class with a pure virtual functions. Now I need to add another class, which doesn't need some method. I got an idea not to implement this method, instead of always throwing an exception when this method is called, like in the next example : #include <iostream> class ibase { pu...
The vtable for base2 is created - you use a base2. The vtable references boo() - so you need to define it. 10.3/8: A virtual function declared in a class shall be defined, or declared pure (10.4) in that class, or both; but no diagnostic is required (3.2).
5,351,823
5,351,840
boost shared_ptr: difference between operator= and reset?
Are there any differences between the two pieces of code below? Is any of them preferable to the other? operator= boost::shared_ptr<Blah> foo; // foo.ptr should be NULL foo = boost::shared_ptr<Blah>(new Blah()); // Involves creation and copy of a shared_ptr? reset boost::shared_ptr<Blah> foo; // foo.ptr should be NULL...
operator= assigns a shared_ptr to a shared_ptr, while reset makes a shared_ptr take ownership of a pointer. So, basically there is no difference between the examples you have posted. That said, you should prefer neither of them and just use make_shared: foo = boost::make_shared<Blah>(); Also, if possible, you can prev...
5,351,965
5,352,085
Which fragment will execute faster / generate fewer lines of code? (C++ / JavaScript)
Which of these is more efficient in terms of speed (number of lines of code generated). var x=obj.mem; x.do1(); x.do2(); or obj.mem.do1(); obj.mem.do2(); I just wrote those in a generic pattern. Specifically, if I have to access a member( or a member of a member ) , is it better to assign the common part to a variabl...
Local variables in JavaScript are faster because The further into the chain, the slower the resolution.
5,352,113
5,352,689
How do I turn a "fat" library into a "non-fat" library?
I'm trying to remove a duplicate object from a library with armv6 and armv7 architectures, i.e., $ lipo -info libx.a Architectures in the fat file: libx.a are: armv6 armv7 As expected, "ar d" does not work directly so I used "lipo -extract" to split the library. However, the resulting libraries are still 'fat' a...
I am not familiar with lipo, but from its man page, it looks like you should be able to do this: lipo libx.a -thin armv6 -output libx-armv6.a lipo libx.a -thin armv7 -output libx-armv7.a
5,352,206
5,352,476
Extract hexdump or RAW data of a file to text
I was wondering if there is a way to output the hexdump or raw data of a file to txt file. for example I have a file let's say "data.jpg" (the file type is irrelevant) how can I export the HEXdump (14ed 5602 etc) to a file "output.txt"? also how I can I specify the format of the output for example, Unicode or UTF? in...
This is pretty old -- if you want Unicode, you'll have to add that yourself. #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { unsigned long offset = 0; FILE *input; int bytes, i, j; unsigned char buffer[16]; char outbuffer[60]; if ( argc < 2 ) { fprintf(stderr, ...
5,352,212
5,352,895
Least annoying way to check auto updates in native app
What would be the best approach? So far I can think of: Super small WinMain exe in HKLM\Run that checks, say, twice a day Windows service that checks, say, twice a day Scheduled tasks (can't seem to find a way to start GUI task via user account, desktop isolation and stuff) Application itself (doesn't work if there ar...
Larry Osterman posted something about this on his blog awhile back. The basic points: Twice a day is WAY too often to check for updates Windows Service is a terrible idea So is a small constantly running WinMain Make sure the user can turn it off easily. Otherwise you're just going to annoy a large subset of your user...
5,352,381
5,352,440
is there some way to deliver some function or operators as parameters?
Is there any way to bring some functional programming to C++ , I want deliver some LAMBDA function or operators as parameter to another function. for example : void test(DWORD foo) { try { __asm { call foo; } } // very weird way, don't think that could work catch (...) { () } } or : void test2(DWORD foo) { s...
You can, by making the parameter of e.g. test a std::tr1::function: void test(std::tr1::function<void(DWORD)> func) { func(0); } You can call this with a function, a member function or even a lambda: test([](DWORD param) { return; });
5,352,451
5,400,093
bjam runtime-link=static
I am trying to compile in a way such that the exec links to gcc statically. I presumed running bjam link=static runtime-link=static should do the trick ? When I tried that I get the following errors like : ...failed gcc.link TGT/bin/gcc-4.5.1/debug/link-static/runtime-link-static/datagen... gcc.compile.c++ TGT/bin/gcc-...
I belive that libstdc++ is intentionally not linked statically. Doing so is considered by many to be filled with peril (though I have not really heard a good reason). I do not think that there is a simple flag that you can add. For the gcc toolset you would add something like -static-libgcc -Wl,-Bstatic -lstdc++ ...
5,352,715
5,357,634
Java to C++ conversion of UI + logic + DB quering
I need some help in pointing me, how to convert* this code below to C++ <html><body> <table> <% while( rs.next() ){ %><tr> <td><%=rs.getString("id") %></td> <td><%=rs.getString("date") %></td> <td><%=rs.getString("email") %></td> </tr> <%}%> <%} catch(Exception e){e.printStackTrace();} finally{ if(con!=null) con.close...
I hope this helps as an introduction to interpreting web scripting languages. JSP (and ASP and PHP) are actually "Inside-Out Code"[1]. They look like code embedded in text, but that is just an illusion...... <%=EXPRESSION%> becomes <%Response.Write(EXPRESSION)%> <% STATEMENTS %> becomes "); STATEMENTS; Response.Write(...
5,352,717
5,352,996
c++ convert string and int to char* not using the C standard library
not using the C standard library do this in C++ ? Convert string to char* Covert int to char* If i had to convert string to int in c++ use something like this #include<iostream> #include<string> #include<sstream> using namespace std; int main() { int num; string str="2020"; (stringstream)"2020">>num...
#include <sstream> #include <iostream> #include <string> int main (int argc, char* argv[]) { std::string str ("123"); const char* c_str = str.c_str(); char* so_bad = const_cast<char*>(c_str); std::stringstream ss; ss << so_bad; int int_value; ss >> int_value; std::cout << int_value;...
5,352,757
5,352,979
Boost asio socket: how to get IP, port address of connection?
I have a TCP server using boost asio. I have accepted a socket connection. How to get IP, Port of machine my server is communicating with? BTW: Is it possible to get info on what ip that connected server user sees my server4 machine?
You can get the IP and port like this: std::string sClientIp = socket().remote_endpoint().address().to_string(); unsigned short uiClientPort = socket().remote_endpoint().port();
5,352,762
5,352,927
Different behaviour running from command line to "Run without Debugging"
Scratching my head here: I have an application which works fine in Debug+Release if started from Visual Studio 2010, in both Debug and "Run without Debugging". If I run the same app from the command line, with the same settings, I see a different behaviour though. In particular, the code that runs differently is: const...
I suspect that the problem is related to an uninitialized heap memory block. The main difference between starting it without debugging and attaching it to the debugger and starting it from the debugger is that in the second case the Windows debug heap is used. The Windows Debug Heap pre-fills the memory handed to the c...
5,352,913
5,353,127
Using c++ in iOS application(memory management)
So... When you use C++ inside iOS app should you handle all the memory management by yourself or does it really matter? Sorry if this question is dumb.
Use C++ memory management for C++ objects; use Objective-C memory management for Objective-C objects. Basically, you need to manage all your memory somehow or other. What you do to free/delete/-release a block or object depends entirely on whether you malloc/new/-alloc to create it.
5,353,057
5,419,462
Finding heap corruption
This is an extension of my previous question, Application crash with no explanation. I have a lot of crashes that are presumably caused by heap corruption on an application server. These crashes only occur in production; they cannot be reproduced in a test environment. I'm looking for a way to track down these crashes....
Use the debug version of the Microsoft runtime libraries. Turn on red-zoning and get your heap automatically checked every 128 (say) heap operations by calling _CrtSetDbgFlag() once during initialisation. _CRTDBG_DELAY_FREE_MEM_DF can be quite useful for finding memory-used-after-free bugs, but your heap size grows mon...
5,353,141
5,353,303
What does this C++11 code (memoize) do?
I found an article that contains this code: template <typename ReturnType, typename... Args> std::function<ReturnType (Args...)> memoize(std::function<ReturnType (Args...)> func) { std::map<std::tuple<Args...>, ReturnType> cache; return ([=](Args... args) mutable { std::tuple<Args...> t(args...); ...
This is simple C++1x implementation of memoization. The memoize function returns a closure. The return value is a function that has state other than what is passed through the arguments (in this case, the cache variable). The [=] bit in the anonymous function indicates that the returned function should take a copy of ...
5,353,161
5,361,723
How do I get the job object (if any) for my current process?
In the context of Windows Job Objects, how can I get the job object for the current process (in case it is in a job object)? The IsProcessInJob function lets me test whether a given process (e.g. the current one) is in a given (or any) job - but it doesn't yield the handle of the matching job.
If you just want to find out what quotas/limits you are running under, or enumerate all the other processes in the job, you don't need to get the Job object for the current process. You can call QueryInformationJobObject with NULL, which will be the Job object of the current process. QueryInformationJobObject: http://...
5,353,263
5,354,047
How do I track down a Windows USER object leak?
I have a program that is leaking USER objects which can be seen in Task Manager. Is there a way to determine which type of resource is being leaked? I've used programs like GDI View for GDI leaks which breaks it down by object type. Is there anything similar to this for USER objects?
There's a debugger called windbg. It can do these sorts of things but the learning curve is staggering.
5,353,287
5,353,379
How to use struct as key in std::map
I want to use a std::map whose key and value elements are structures. I get the following error: error C2784: 'bool std::operator <(const std::basic_string<_Elem,_Traits,_Alloc> &,const _Elem *)' : could not deduce template argument for 'const std::basic_string<_Elem,_Traits,_Alloc> &' from 'const GUID I understand th...
You can define the comparison operator as a freestanding function: bool operator<(const GUID & Left, const GUID & Right) { // comparison logic goes here } Or, since in general a < operator does not make much sense for GUIDs, you could instead provide a custom comparison functor as the third argument of the std::ma...
5,353,291
5,353,451
Multiple inheritance without virtual functions in c++
I came across the diamond problem and found different solutions for different cases with a single diamond. However I couldn't find a solution for 'chained' diamonds. According to the structure: yes, I want to have multiple baseclasses everytime, so virtual inheritance isn't a solution (is it even called diamond then?)....
s->kid1::val does not mean "val from the kid1 subobject". It's just a name qualified by the type (not the subobject) that contains it. I don't know why country1::kid1 is even accepted at all, but apparently it's a typedef for ::kid1. Two data members in world both have the qualified name ::kid1::val. What you want is...
5,353,401
5,353,560
Autotools: Generating Sources and Headers in Makefile.am
This link mentions wildcards as a way to automatically list the SOURCES and HEADERS in the Makefile.am file. It also mentions that some people write external scripts to generate those files. Do you know of the standard way of automatically including all the *.h *.cpp here, or should I just write my own Perl script to g...
Automake won't add this feature. It makes assumptions that a particular .h or .cpp file is associated with a particular project. That assumption holds for a number of common project layouts and fails for any layout that differs. For example, I've had projects that were laid out as src/module/code src/app/code src/lib...
5,353,466
5,354,390
How do I read input from files?
I am trying to read input from file into an array. I seem to have done the needful, yet the code is not working as it should. Please tell me where am i going wrong. This s my code: int pb[10][10]; int i,j,n; string ip_filename = string("pro.txt"); ifstream fil1; fil1.open(ip_filename.c_str()); // to store th...
This code works perfectly fine for me with pro.txt formatted like you show: #include <iostream> #include <fstream> #include <string> using namespace std; int main() { int num_rows = 4; int num_cols = 4; int pb[10][10]; int i,j,n; string ip_filename = string("pro.txt"); ifstream fil1; fil...
5,353,779
6,626,525
Xcode 3.2.6 and 4 linker errors ld:bad codegen, pointer diff in ... to global weak symbol
I have very strange errors with Xcode 3.2.6 and Xcode 4. Xcode 3.2.5 does not have the errors in my project. Symbol hidden by defaults option is set to YES. These link errors are related to static members (pointers) inside template classes. Any ideas, compiler/linker keys to check, anything?
This has to do with symbol visibility in the libraries you have compiled. The GCC 4.0 switch -fvisibility=hidden option is intended to hide symbols for DSO/shared object libraries to reduce link/load times. However, I have seen some blogs online using the switch in some peculiar manner when compiling static libraries...
5,353,785
5,353,814
C++: How do I change the default destination of stdout?
I have a library that outputs stuff to the console. How do I change stdout such that it writes to a file instead of to the console?
Try the following: // Let fs be your file stream … cout.rdbuf(fs.rdbuf()); This re-sets the internal stream buffer.
5,353,792
5,353,880
do-while condition without declaring a separate variable
I have a do-while loop inside a function that resembles something like this: do { // a bunch of stuff if (something < something else) { return true; } else if (stuff > other stuff) { if (something != other stuff) { return false; } else ...
Assuming your code is incorrect due to you trying to paraphrase it, this is what you should be doing to meet your needs of the return being the same as the while(); To others, this code below is incorrect logic, but I am trying to keep it in the similar pseudo code he utilized. Basically if you want the while to mimic ...
5,353,832
5,354,085
Setting Visual C++ Studio/Express to strict ANSI mode
I generally program & compile under Linux with gcc and -ansi flag; but I've been forced with doing a job in Visual C++ and whenever I compile my C code I get all the Microsoft warnings like 'fscanf': This function or variable may be unsafe. Consider using fscanf_s instead. I get these despite following some step...
One way to suppress specific warnings is to add something like the following to the source. #if defined( _WIN32 ) #pragma warning(disable:4996) #endif
5,353,925
5,354,169
Why does my output go to cout rather than to file?
I am doing some scientific work on a system with a queue. The cout gets output to a log file with name specified with command line options when submitting to the queue. However, I also want a separate output to a file, which I implement like this: ofstream vout("potential.txt"); ... vout<<printf("%.3f %.5f\n",Rf*BohrTo...
You are getting your C and C++ mixed together. printf is a function from the c library which prints a formatted string to standard output. ofstream and its << operator are how you print to a file in C++ style. You have two options here, you can either print it out the C way or the C++ way. C style: FILE* vout = fopen("...
5,354,063
5,354,486
How to initialize an std::string using ""?
I'm facing problems with initializing a std::string variable using "" (i.e. an empty string). It's causing strange behavior in code that was previously working. Is the following statement wrong? std::string operationalReason = ""; When I use the following code everything works fine: std::string operationalReason; oper...
What happens if you just do std::string operationalReason;? That should have the same effect as the two examples you provided. If in fact you're experiencing problems when you use the std::string operationalReason = ""; form that may indicate that the string data storage has been corrupted, but it may equally mean that...
5,354,130
5,354,234
Concatenate Strings in C/C++
How do I concatenate Strings with C/C++? I tried the following ways: PS: errorInfo is a char * I should return it. errorInfo = strcat("Workflow: ", strcat( workflowToString(workflow).utf8(), strcat(" ERROR: ", errorCode.utf8))); sprintf(errorInfo, "Workflow %s ERROR: %s"...
According to this page strcat does the following: Appends a copy of the source string to the destination string. The terminating null character in destination is overwritten by the first character of source, and a new null-character is appended at the end of the new string formed by the concatenation of both in destin...
5,354,194
5,354,530
How do I change the default local time format in C++?
I have a function: string get_current_time() { time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); return asctime (timeinfo); } which returns time in the following format: Fri Mar 18 11:25:04 2011 How do I change it so that it is returned in the following...
As @0A0D suggested, whilst you can't change asctime, you can use strftime to format the data contained in your time_t: string get_current_time() { time_t rawtime; struct tm * timeinfo; time ( &rawtime ); timeinfo = localtime ( &rawtime ); char output[30]; strftime(output, 30, "%Y %m-%d %H-%M-%...
5,354,243
5,361,608
Open a DBX and BAT Outlook Files
Hi guys I need to read some email from outlook in a C++ program, after that based on the content of email, I'll decide to reply or not. I suppose I need to open Dbx outlook files, but how? thx
DBX files are Jet Blue ESE database files You can find the documentation here: http://msdn.microsoft.com/en-us/library/gg269245(EXCHG.10).aspx Or you may find it easier to use the Outlook Express libraries directly: http://msdn.microsoft.com/en-au/library/bb931229(VS.85).aspx There currently appears to be a problem...
5,354,314
5,354,352
How can I completely disable calls to assert()?
My code is full of calls to assert(condition). In the debug version I use g++ -g which triggers my assertions. Unexpectedly, the same assertions are also triggered in my release version, the one compiled without -g option. How can I completely disable my assertions at compile time? Should I explicitly define NDEBUG in ...
You must #define NDEBUG (or use the flag -DNDEBUG with g++) this will disable assert as long as it's defined before the inclusion of the assert header file.
5,354,368
5,354,385
Relation between 'This' Pointer and Vtable Functions
I do not have much idea about the functionality of the Virtual Table, but in the code pasted below - the this pointer passed is obviously points to different locations in the 2 cases - but the function show() in the memory - is it instantiated/meaning created separately for every object at Runtime? (Forgive my poor und...
A does not have a vtable at all (or it shouldn't on any good compiler) because it is not a polymorphic class: it has no virtual member functions. The function show() exists in the executable exactly once. Member functions aren't really different from ordinary nonmember functions, they just have an extra, implicit thi...
5,354,379
6,707,919
a simple way to add or modify glyphs in true type fonts (TTF)
I'm looking for a simple way to add a glyph to an existing true type font. I'm wondering if there exists a library (C++ or C#) or a command line tool to support that functionality because generating a TTF from scratch seems to be a really complex task. The background for this question is that we would like to develop a...
To the best of my knowledge, I have not seen such a commandline tool/library. Generating a font may be complex but modifying an existing font can be just as bad. When you add a glyph to an existing font, you will need to specify additional things along with it( e.g. unique character code, metrics values, etc). Furtherm...
5,354,427
5,356,197
C++ unit testing using a scripting language
I would like to utilize some scripting language in order to perform unit testing of the C++ code. It could be easier to develop tests in a scripting language given that it has access to the required C++ functions. I have either Ruby or Perl in mind (because I am familiar with them). It seems that I could use SWIG to ...
Inline:CPP provides a relatively simple means of calling C++ code from Perl. I recommend running your script using the following (or with an equivalent directive inside of the test script): perl -MInline=FORCE,NOISY,NOCLEAN test.pl
5,354,459
5,354,657
C++ How to get the Image size of a png file (in directory)
Is there a way of getting the dimensions of a png file in a specific path? I don´t need to load the file, I just need the width and height to load a texture in directx. (And I don´t want to use any third-party-libs)
The width is a 4-byte integer starting at offset 16 in the file. The height is another 4-byte integer starting at offset 20. They're both in network order, so you need to convert to host order to interpret them correctly. #include <fstream> #include <iostream> #include <winsock.h> int main(int argc, char **argv) { ...
5,354,668
5,355,001
C++/Boost string replace: How do I replace '&' with '&amp;' only when & ends with a ;
I'm doing a replace for xml and I need to replace a & character with the &amp; only when the & character does end with a semi-colon. Surely I can do this with replace_if, replace_all, or maybe the regex support in boost, but I any feeling dumb today...can't seem to find what I need. Suggestions?
It shouldn't be that hard. Use std::find to advance to the next &, then scan ahead using find_if, find_first_of or boost::regex to find either the ';', or something that would make you stop searching. Something like the following (untested) should work: struct EndMatch { bool operator()( char ch ) const { ...
5,354,841
5,355,147
How redirect stdout (stderr) of child process to socket in winapi?
I want to make client-server program where server is main process and the client is child process. In client I want to redirect stdout and stderr streams of child process to socket. In server I want to make from socket file descriptor and read from it. In internet there is lot of info about sockets, but I havn't found ...
Take a look at Netcat if you can use this or find the source for the windows version somewhere on sourceforge probably this can use pipes to intercept stdin/stdout and send to and read from sockets with those pipes. I know you said no pipes but there is no other way to do this with only windows API. You'll need the fo...