c++

using user input such as YES and NO to control program flow in C++

Hi, I'm making a small program that uses a if else statement, but instead of using numbers to control the flow i want to be able to make the control work with with yes and no; for example: cout << "would you like to continue?" << endl; cout << "\nYES or NO" << endl; int input =0; cin >> input; string Yes = "YES"; string No = "NO"; i...

Changing http traffic by using LSP problem?

Hello! I try change and add some data to http traffic by using LSP. To do that i use LSP sample from Windows PlatformSDK and change lpBuffers variable in function WSPRecv in spi.cpp. When i only replace data in lpBuffers than all work fine. But when i try add data to lpBuffers than lpBuffers is change, but real traffic not changing. Anyb...

Converting class function pointer to void* or vice versa

Im trying to compare the address of two functions for equality. Type of my stored function is known. This system normally works, consider the following code (written as sample not from the program): virtual bool compare(void *fn2) { void (*fn)(int); if(fn==fn2) return true; } However when class functions came into considerat...

possible to have a Timeout on ReadFile()?

while(GetExitCodeProcess(processInfo.hProcess, &exitCode) && exitCode == STILL_ACTIVE) { ReadFile(defaultSTDIN, chBuf, 1, &dwRead, 0); WriteFile(writingEnd, chBuf, 1, &dwWritten, 0); } The problem with the code above is that even when the child process referenced through processInfo.hProcess has exited, we are still stu...

Recording and charting boot process information in Linux

Hello everyone. I need to write a command line tool that records the boot process information in Linux, and then renders it in a chart format (a textual chart would do). How do I programmatically obtain the this boot process information? Languages that I am allowed to use are C and C++. Thanks in advance. :-) ...

Getting the actual length of a UTF-8 encoded std::string?

my std::string is utf-8 encoded so obviously, str.length() returns the wrong result. I found this information but I'm not sure how I can use it to do this: The following byte sequences are used to represent a character. The sequence to be used depends on the UCS code number of the character: 0x00000000 - 0x00000...

C++ rendering or game engine for Android.

Hello. I'm developing an Android application and I need to use a render engine to show some objects that I made with Blend. I'm wondering if there is a C++ game engine or render engine to show my models. Is there anyone? Thanks. ...

How does stringstream work internally?

I'm asking in context of performance. Is stringstream simply a string/vector, so writing to it may result in its whole content being copied to a bigger chunk of memory, or is it done in a more tricky way (say, a list of strings or whatever)? ...

Logging Guard to limit semi-constant log messages

I'm using boost log in my application for logging. However, in some sections of my code I have some log statements that could occur very often if something goes wrong. I'd want some kind of guard that can limit log messages when it detects that the same log message appears constantly. e.g. (This is a simplified example, not actual impl...

c++ crashes on writing public variable

I wrote a simple test program in c++ but why does this crash on: s[i] = s[i] - 'a' + 'A'; with the exception: Access violation writing location 0x01327808 #include "stdafx.h" #include <iostream> using namespace std; class String { public: char *s; int len(); void upper(); String(char*); }; String::String(char*x) { s = ...

MFC - dim main window when showing modal dialog

I have a fairly standard MFC application that consists of a main window, and occasionally brings up modal dialogs. As we all know nothing can be done outside a modal dialog until it is closed. Therefore, a nice UI feature is to "dim" the rest of the main window behind the dialog, to visually indicate you can't use it until you're done ...

When a RAII object fails to construct

Suppose I construct a RAII object, and that object may fail to construct. How do I handle this? try { std::vector<int> v(LOTS); // try scope ends here because that's what the catch is for } catch( const std::bad_alloc& ) { // ... } // v? what v? Granted, the default constructor of std::vector won't throw and that can help,...

Deletion of Custom Array Causes Heap Error.

TL;DR Boost-Test-Framework crashes with no error given while passing all tests and leaking all memory. Test fails multiple times with mentioned destructor implementations. Clear function also throws heap error. What are we doing wrong with the dtor? TL;DR This is pertaining to a college homework assignment, and my friend's solution ...

Windows Explorer Context Menu

I want to add a context menu entry with C++. I've been searching but all I can find is some jackass trying to sell me some BS program that does it for me which is not what I am looking for. I'm not looking for anything that uses .NET or Visual C++ either. I want the straight C++ way of doing this. ...

Fast controled copy from istream to ostream

I have to copy several bytes from a istream to a ostream, there are 2 ways that I know to perform this copy. myostream << myistream.rdbuf(); and copy( istreambuf_iterator<char>(myistream), istreambuf_iterator<char>(), ostreambuf_iterator<char>(myostream) ); I've found that rdbuf version is at least twice as fast as th...

Converting UTF-8 with C++ standard libraries (no /clr)

I have a string like this: "These are Pi (\u03a0) and Sigma (\u03a3).". How can i convert this to contain and print effective characters, using C++ standard libraries? This solution http://msdn.microsoft.com/en-us/library/system.text.encoding.utf8(VS.80).aspx, use .NET framework (/clr compiling), that i want to avoid preferring C++ stan...

What is the difference between the standard library and the standard template library?

Hello, I keep seeing reference to both the C++ standard Library and the C++ Standard Template Library (STL). What is the difference between them? Wiki mentions that they share some headers but that's about it. Thanks ...

no match for ‘operator<<’ in ‘os << "Test Failed ["’ when os is an ostream &

Edit: I incorrectly used #include <stdio.h> when I needed to include <iostream>. This happened mostly because I was integrating some C style code with a larger C++ program. EndEdit I'm using a simple test framework for my college class, but whenever I use the provided preprocessor macro I get these two errors. I've expanded the macro ...

ARRAYSIZE C++ macro: how does it work?

OK, I'm not entirely a newbie, but I cannot say I understand the following macro. The most confusing part is the division with value cast to size_t: what on earth does that accomplish? Especially, since I see a negation operator, which, as far as I know, might result in a zero value. Does not this mean that it can lead to a division-by-z...

One single class for const and non-const iterators. Is it possible?

Hi there, guys! I'm implementing a custom container with an STL-like interface for a 3D grid control for my scientific software. This is my second question regarding the iterator class for this container. Thanks for helping me with the first! My question is just like "How do you avoid code duplication when implementing const and non-co...