c++

include file error in C++

Problem fixed! Thanks a lot for the constructive suggestions! I am unable to figure out what is the mistake in the following code. Is there something wrong with the way I am doing includes? // This is utils.h #ifndef UTILS_H #define UTILS_H #include <iostream> #include <fstream> #include <stack> #include <queue> #include <vector> #inc...

Boost::Random and Enumerated Types

Right now I'm generating a random enumerator using boost's random library. Basically I'm using an implicit conversion to specify the random generator's distribution, getting a random number, and then casting that back to the enumerated type. Ex: (minColor and maxColor are parameters of the enumerated type) boost::mt19937 randGen(std::t...

Linking error in C++

Problem fixed. Thanks a lot! I am having the following error in the code shown below: Error is as follows: $ g++ main.cpp Neighbor.cpp Graph.cpp /tmp/ccclDcUN.o: In function main': main.cpp:(.text+0xc1): undefined reference to Graph::add(int, Neighbor&)' main.cpp:(.text+0xd3): undefined reference to `Graph::add(int, Neighbor&)' collec...

setting strings in gdb

c++: int main() { string a = "a"; ... ... } when i debug in gdb: (gdb) set var a = "ok" Invalid cast I run the program and pause at a break point after string a has been initialized. I'm trying to set its value, but it complains about invalid cast. What's the proper syntax for this? ...

Is is better to do const pass by references over non-const pass by references?

I came across this. http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml?showone=Reference_Arguments#Reference_Arguments According to the style guide, only const references are allowed as parameters. (That's what I understood) Although, I don't seem to like that approach. Comments? ...

Is it possible to deallocate a statically defined array?

Can you release the memory of an array defined with static allocation? ...

How to read unsigned short from file?

I have a bitmap image that I am parsing and I need to be able to open the file and store the first unsigned short. I tried to accomplish this using FILE and fscanf() but fscanf() always fails and returns 0 (number of items successfully read). FILE *pFile = fopen ( fileName->c_str() , "r" ); if ( pFile == NULL ) { cerr << "couldn't...

Parameters Naming for Constructor

In Java, usually, I can have my constructor's parameters same name as member variables. public A(int x) { this.x = x; } private int x; In C++, I can't. Usually, I have to do it this way. public: A(int x_) : x(x_) { } private: int x; Is there any better way? As the constructor parameters name look ugly, when I...

std::copy problem when reading matrix from file

I dont know why the entire matrix gets stored in the first row itself. The loop does actually get called N times if there are N rows. and this is matrix.dat 5 1 2 3 1 2 0 100 3 4 0 5 6 -1 0 9 10 11 #include <fstream> #include <iterator> #include <vector> #include <iostream> int main() { std::vector<std::vector<int> > matrix; ...

C++ Preprocessor metaprogramming: obtaining an unique value?

Hi, I'm exploiting the behavior of the constructors of C++ global variables to run code at startup in a simple manner. It's a very easy concept but a little difficult to explain so let me just paste the code: struct _LuaVariableRegistration { template<class T> _LuaVariableRegistration(const char* lua_name, const T& c_name) { ...

NULL Pointer Problem?

void Insert(AVLnode * & root, string X) { if ( root == NULL) { root = GetNode(X); } else if ( root->info > X ) { Insert(root->left,X); if ( height(root->left) - height(root->right) == 2 ) if ( X < root->left->info ) RotateRR(root); else RotateLR(root); } else if ( root-...

Question about file transfer for socket programming

Is there a good method on how to transfer a file from say... a client to a server? Probably just images, but my professor was asking for any type of files. I've looked around and am a little confused as to the general idea. So if we have a large file, we can split that file into segments...? Then send each segment off to the server. S...

Get the number of elements in a pointer to a char array in C++

I realise this is an incredibly noob question, but I've googled for it and can't seem to find an answer (probably because I've worded the question wrong... feel free to fix if I have) So I have this code: int main(int argc, char* argv[]) { puts(argv[1]); return 0; } It works fine if I've passed a parameter to my program, but ...

C\C++ open source PCM to Mp3 convertor?

C\C++ open source PCM to Mp3 convertor/encoder? What do I need Open Source Libs/wrappers for encoding/decoding. Tutorials and blog articles on How to do it, about etc. ...

Symbian Development.

Hi All, I am currently doing iphone development. I wish to do development in the Symbian platform too. Rather than Java i am familiar with CPP. Can you please help me by giving me some advice to get start in this development environment.? What all are the softwares i need to get installed in my system.? Expecting a positive reply. Than...

C++/WinInet Change Proxy Settings Windows 7

[Disclaimer: this is a Windows 7 specific issue as far as I can tell] I've got a block of code that changes the proxy settings in the Windows registry, then proceeds to call the WinInet API with the following: InternetSetOption(NULL, INTERNET_OPTION_SETTINGS_CHANGED, NULL, 0); InternetSetOption(NULL, INTERNET_OPTION_REFRESH , NULL, 0);...

Can't lua_resume after async_wait ?

Hi, I have some lua script that have some long running task like getting a web page so I make it yield then the C code handle get page job async, so the thread free to do other job and after a specify time it check back to see is the get page job finished , if so then resume the script. the problem is the thread can't resume the job afte...

what exactly is dynamic casting in c++

can anyone tell what exactly is dynamic casting means in c++. where exactly can we use this dynamic casting? this was asked to me in the interview and i went blank for this question:). ...

How to write mp3 frames from PCM data (C/C++)?

How to write mp3 frames (not full mp3 files with ID3 etc) from PCM data? I have something like PCM data (for ex 100mb) I want to create an array of mp3 frames from that data. How to perform such operation? (for ex with lame or any other opensource encoder) What do I need: Open Source Libs for encoding. Tutorials and blog articles on ...

Order of destruction for Array of Objects

class MyClass { }; void foo { MyClass arr[10]; } I want to know the order of destruction of array objects when function returns. I read it More Effective C++ about it and it says that destructor are invoked in reverse order to that of constructor order as follows: for(int i = 9 ; i >= 0 ;i--) { arr[i].MyClass::~MyClass(); ...