c++

Passing references to pointers in C++

As far as I can tell, there's no reason I shouldn't be allowed to pass a reference to a pointer in C++. However, my attempts to do so are failing, and I have no idea why. This is what I'm doing: void myfunc(string*& val) { // Do stuff to the string pointer } // sometime later { // ... string s; myfunc(&s); // ......

Multiple threads reading from the same file

My platform is windows vista 32, with visual c++ express 2008 . for example: if i have a file contains 4000 bytes, can i have 4 threads read from the file at same time? and each thread access a different section of the file. thread 1 read 0-999, thread 2 read 1000 - 2999, etc. please give a example in C language. ...

How to get hardware MAC address on Windows

I'm playing around with retrieving the MAC address from the NIC - there are a variety of ways to get it, this article covers the most common: http://www.codeguru.com/Cpp/I-N/network/networkinformation/article.php/c5451 I'm currently using the GetAdaptersInfo method, which seems the most bulletproof, but if the MAC address has been set ...

Multi-dimensional vector

Hai C++ How to create a 2D vector where in like 2D array a[0][1]=98; a[0][2]=95; a[0][3]=99; a[0][4]=910; a[1][0]=98; a[1][1]=989; a[1][2]=981; a[1][3]=987; how do the same in vector? Thank you in advance. ...

How to show command line build options in Visual C++ 2008

In MSVC 2008 project, building a project will display following information in output window: 1>------ Build started: Project: Project1, Configuration: Debug Win32 ------ 1>Compiling... 1>main.cpp 1>test1.cpp 1>test2.cpp 1>Generating Code... 1>Linking... 1>LINK : test.exe not found or not built by the last incremental link; performing f...

What's the point in defaulting functions in C++0x

C++0x adds the ability for telling the compiler to create a default implementation or any of the special member functions, while I can see the value of deleting a function where's the value of explicitly defaulting a function? Just leave it blank and the compiler will do it anyway. The only point I can see is that a default constructor ...

Is it possible to use boost.any as a key in a std::map(or something similiar)?

std::map<any, string> is not working so I wonder if there's another approach to have arbritary keys? ...

What to do as a novice programmer?

So...As a senior year computer engineer in college, I was wondering if you guys had any ideas of what I should do to gain more experience? I took a intro to C++ class, and are proficient in C++, Verilog, Python and Bash scripting. I will be taking a bunch of programming classes in the Fall (Operating Systems, Algorithms, C# Programming,...

Working with string streams?

Say i have a stringsteam in C++, and I want to do different operations to it like: Searching for a sequence of characters, Converting block of text into int (in the middle of the line), Moving the get pointer back and forth and so on. What is the standard/common way of doing this kind of things with stringstreams? ...

How to check whether STL iterator points at anything?

I want to do something like this: std::vector<int>::iterator it; // /cut/ search for something in vector and point iterator at it. if(!it) //check whether found do_something(); But there is no operator! for iterators. How can I check whether iterator points at anything? ...

Which compilation option should be set for profiling?

Hi, I need to profile an application compiled with intel's compiler via VC++. I'm using VTune to profile my code. My understanding is that in release mode I won't have the debug information that is necessary for the profiler to profile my code while in debug mode, the result of the profiling will not be pertinent. What should I do ? I...

What does the following C++ struct syntax mean..

If I have a C++ struct, defining a 64bit data word such as.. struct SMyDataWord { int Name : 40; int Colour : 24; }; What does the : 40 syntax mean... does it mean that the first 40 bits are reserved for the Name and the remaining 24 bits for the Colour? This is how it appears to be being used, but I've not come across it be...

Why are empty expressions legal in C/C++?

int main() { int var = 0;; // Typo which compiles just fine } ...

Variadic recursive preprocessor macros - is it possible?

I've run into a little theoretical problem. In a piece of code I'm maintaining there's a set of macros like #define MAX_OF_2(a, b) (a) > (b) ? (a) : (b) #define MAX_OF_3(a, b, c) MAX_OF_2(MAX_OF_2(a, b), c) #define MAX_OF_4(a, b, c, d) MAX_OF_2(MAX_OF_3(a, b, c), d) ...etc up to MAX_OF_8 What I'd like to do is replace them wi...

g++ rejects my simple functor with "expected a type, got 'xyz'"

I've been playing about with functors in C++. In particular, I've got a vector of pairs I'd like to sort by the first element of the pair. I started off writing a completely specialised functor (i.e. something like "bool MyLessThan(MyPair &lhs, MyPair &rhs)"). Then, just because this sort of stuff is interesting, I wanted to try writing ...

Pimpl idiom vs Pure virtual class interface

I was wondering what would make a programmer to choose either Pimpl idiom or pure virtual class and inheritance. I understand that pimpl idiom comes with one explicit extra indirection for each public method and the object creation overhead. The Pure virtual class in the other hand comes with implicit indirection(vtable) for the inheri...

Neural network XOR backpropagation info needed.

Does anyone know where I can find some sample codes about the NN Back propagation for XOR, that I can also test the system after it was trained? Preferably in C++ or MATLAB. ...

Casting an array of unsigned chars to an array of floats

Hi. What is the best way of converting a unsigned char array to a float array in c++? I presently have a for loop as follows for (i=0 ;i< len; i++) float_buff[i]= (float) char_buff[i]; I also need to reverse the procedure, i.e convert from unsigned char to float (float to 8bit conversion) for (i=0 ;i< len; i++) char_buff[i]...

How to list SQL 2005 Express instances

I would like to list what instances of SQL 2005 Server (Express Editon) are installed on local or remote machine (my app is in Native C++). I found that i can make it by SQLDMO, however it seems that SQLDMO does not see SQL 2005 Express Edition and call to ListAvailableSqlServers returns empty list. How can i make it? Playing with syste...

CInternetSession::OpenURL on Windows Mobile causes error 12029 (cannot connect)

I'm trying to access data using HTTP by calling CInternetSession::OpenUrl on Windows Mobile 5 (coding in C++ with MFC). I always get an exception with error code 12029 (cannot connect). I suspect that I need to use the Connection Manager API to create a connection first. Can someone confirm that? I am going to try coding it up, based o...