c++

cin.get() not working

I wrote this simple program today, but I found that cin.get() refuses to work unless there are 2 of them. Any ideas? #include <iostream> using namespace std; int main(){ int base; while ((base < 2) || (base > 36)){ cout << "Base (2-36):" << endl; cin >> base; } string base_str = "0123456789abc...

C++ Template Basics - Function Accept Sub Class or Super

Say you have a sub class B which inherits from super class A. You want a function that can accept either A or B. template <typename T> void someFunc(T* pObj, bool someOtherArg) { pObj->AnInheritMethod(); if (pObj->IsASub()) { pObj->ANonInhertMethod(); } } When I compile this (Visual Studio 6) I get: error C206...

Integrating a script language into a C++ application

Hi, I'm really new to C++ and I've come across a problem I've not been able to solve by reading documentations. I want to embed a script language into my c++ application. That language could be javascript, lua or preferably python. I'm not looking for something like Boost.Python / swig, something that is able to wrap my c++ functions ...

What does (a+b) >>1 mean?

What does int c = (a+b) >>1 mean in C++? ...

c2955 error on my Double Link List project

Okay, I'm making a project that implements a Double Linked List using classes, templates and structures. I constantly get the error: doublelinklist.h(21) : error C2955: 'Node' : use of class template requires template argument list when declaring the head and tail of a node in the LinkedList class. DoubleLinkList.h: #ifndef DOUBLEL...

Obfuscated way of accessing a character in string

I found today interesting piece of code: auto ch = (double(), (float(), int()))["\t\a\r\n\0"]["abcdefghij"]; which works same as: char str[] = "abcdefghij"; char ch = str['\t']; Why is it even possible? Especially why is the compiler picking first char from string and using it as subscript instead of throwing error? ...

Conflict between providing (optional) functionality and encapsulation?

I need to provide a certain operation on the elements of my class Foo. This operation is specific and weird enough that I don't really want to make it a member function. On the other hand, it works on the internals of the class, which I don't want to expose. Here is the class: class Foo { typedef std::map<int,double> VecElem; std::...

Keeping modules independent, while still using each other

A big part of my C++ application uses classes to describe the data model, e.g. something like ClassType (which actually emulates reflection in plain C++). I want to add a new module to my application and it needs to make use of these ClassType's, but I prefer not to introduce dependencies from my new module on ClassType. So far I have ...

spawnv call with array of array of char (char* argv[])

hi, id like to spawn a process with unknown number of parameters. my code so far (using power++): char** psaParameters = new char*[ saParameters.GetCount() ]; for( int i = 0; i < saParameters.GetCount(); i++ ) { psaParameters[ i ] = new char[ saParameters[ i ].GetLength() ]; strc...

How are iostream objects cin, cout, cerr, and clog implemented?

iostream objects cin, cout, cerr, and clog are objects declared in the iostream header. I'm aware that it's possible in some compilers to attempt to use these iostream objects before they are constructed, so under some circumstances they must be subject to the "static initialisation order fiasco". In those compilers where it's always s...

C/C++, negation operator frustration

In the following code segment what will be the result of the function, value of x , value of y { unsigned int x=-1; int y; y = ~0; if(x == y) printf("same"); else printf("not same"); } Please explain how this works. From my side its answer will be "not same" but its actual answer is "same". ...

String reversal in C++

I am trying to reverse the order of words in a sentence by maintaining the spaces as below. [this is my test string] ==> [string test my is this] I did in a step by step manner as, [this is my test string] - input string [gnirts tset ym si siht] - reverse the whole string - in-place [string test my is this] - reverse t...

Using the "This" Pointer in c++

I've been reading about the "this" pointer on various sites (e.g. the MSDN manuals) and understand its basic uses -- returning a copy your own object or using a pointer of it for returns/comparison. But I came across this statement: // Return an object that defines its own operator[] that will access the data. // The temp object is...

How to find assignments with no effect?

In the process of automatically renaming many variables in a big project I may have created a lot of things like these: class Foo { int Par; void Bar(int Par) { Par = Par; // Nonsense } }; Now I need to identify those locations to correct them. E.g. into "this->Par = Par;". Unfortunately the Visual C++ Compil...

Upload a file to a web server using C++

Hi, I want to upload files from a client location to a server. At present, I have a client-server socket program by which I could send/receive files across, but I would like to improvise it. My idea would be to transfer the file using HTTP PUT/POST from client (most of the coding on client side) to the server. Since I have no idea abo...

C++ textbox contents

How do I get the contents of a textbox in C++? ...

Same C++ code results in infinite loop on Windows and expected behavior on OSX

This is one of the weirder things I've seen. I'm teaching an intro C++ course at a university, and one of my students contacted me saying that his code was running forever without stopping. I briefly glanced over his code during class, and didn't see anything immediately obvious, so I had him email me his code. Without making any chang...

add_definitions vs. configure_file

I need to conditionally compile several parts of code, depending on whether there are some libraries present on the system or not. Their presence is determined during the CMake configuration phase and I plan to tell the compiler the results using preprocessor definitions (like #ifdef(LIB_DEFINED) ... #endif). I know about two possibili...

operator overloading c++

hey i am a new programer in c++ and i have an abstract class A, and i implemented operators in it. and now i have two classes B and C that extend A. for some reason the compiler does not identify the operators. is it because that operators are not inherrited? or is it because that i have a code bug? here is the code: #ifndef A_ #d...

How to test if preprocessor symbol is #define'd but has no value?

Using C++ preprocessor directives, is it possible to test if a preprocessor symbol has been defined but has no value? Something like that: #define MYVARIABLE #if !defined(MYVARIABLE) || #MYVARIABLE == "" ... blablabla ... #endif EDIT: The reason why I am doing it is because the project I'm working on is supposed to take a string from ...