c++

read words from line in C++

Hey everyone, I was wondering if there was a way to read all of the "words" from a line of text. the line will look like this: R,4567890,Dwyer,Barb,CSCE 423,CSCE 486 Is there a way to use the comma as a delimiter to parse this line into an array or something? ...

Is a bit field any more efficient (computationally) than masking bits and extracting the data by hand?

I have a numerous small pieces of data that I want to be able to shove into one larger data type. Let's say that, hypothetically, this is a date and time. The obvious method is via a bit field like this. struct dt { unsigned long minute :6; unsigned long hour :5; unsigned long day :5; unsigned long month :4; unsigned...

Should I expose iterators and adaptor methods or a whole container in C++?

Consider the piece of code: class Foo { // ... std::vector<Bar> bars; }; Should I expose the whole container, or should I expose typedef'd iterator class and write adaptor methods (begin(), end(), size(), and whatever I need)? If the answer is it depends, how should one make a decision? ...

How do you get an unsigned long out of a string?

What's the safest and best way to retrieve an unsigned long from a string in C++? I know of a number of possible methods. First, converting a signed long taken from atol. char *myStr; // Initalized to some value somehow. unsigned long n = ((unsigned)atol(myStr)); The obvious problem with this is, what happens when the value stored i...

modern c++ style neural network libraries?

Looking for neuronal network libraries (providing the basic multi-layer-perceptron with back-propagation and possibly teachers) i did find only libraries which seem to come from the 1990s and don't use more modern approaches (stl etc.) or small student projects. Did i miss libraries that you know about? update: Support for mnist would ...

edge detection of an image

Hello everyone, I have written a code to detect edges using double thresholding,what i am doing here is if the higher threshold image has a pixel value of 255 then it is valid and if the lower thrsehold image has a connected white pixel to that pixel then it is valid edge. but in my program only the high threshold image is getting copi...

Platform-independent way to obtain maximum C++ float value

What’s the best, platform-independent way to obtain the maximum value that can be stored in a float in C++? ...

How to compile a dynamic library?

Hi, I've been searching the web for a couple of days and can't seem to find clear instructions on how to do this. SQLite doesn't have math functions like, sine, cosine, etc.. I found a library that extends SQLite and adds these functions, but I can't figure out how to compile the library. http://lhealy.livejournal.com/6306.html I've ...

Validating a user's input to make sure it's in binary (C++)

Hey guys, I'm working on a c++ program and I need to take in a binary number from 0-255, inclusive, as a string(it has to be a string). What can I write in a while(input invalid) loop to check that the string is between 00000000 to 11111111, inclusive. Thanks so much ...

C++ map question

I have an integral position-based algorithm. (That is, the output of the algorithm is based on a curvilinear position, and each result is influenced by the values of the previous results). To avoid recalculating each time, I would like to pre-calculate at a given sample rate, and subsequently perform a lookup and either return a pre-cal...

Saving passwords inside an application

I am writing an application that needs to read a user name and password and store them so that the program can read them again later. Storing it in some variables sounds like a stupid idea. Found that KDE library, but it has too huge dependency, and I am too newbie programmer to understand how to use it. What are the common Methods to...

How to require certain concepts in C++ code?

How do I require and check that an argument is a certain concept in C++? For example, the random_shuffle function in the algorithm header requires that its arguments are RandomAccessIterators: template<typename _RandomAccessIterator> inline void random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last) {...

getrusage() get system time, user time. Unix programming help

I am writing a shell where I need to launch several child processes at once and record the system time and user time. So far I am able to do it. The only problem is that I am using wait4 to grab the system resources used by the child program and put it in my rusage structure called usage. How can I launch all the processes at the same ...

Is it safe to use fastcall in a shared library?

For example, let's say I have a function that will swap bytes in a 32 bit value for you: uint32_t byte_swap(uint32_t in); Well it seems silly to push that 32-bit value onto the stack and pop it off again, especially if we're going to be calling this function a lot, so let's pass it in through ECX: #if __FASTCALL_SUPPORTED_ /* Whate...

C++ override/overload problem

I'm facing a problem in C++ : #include <iostream> class A { protected: void some_func(const unsigned int& param1) { std::cout << "A::some_func(" << param1 << ")" << std::endl; } public: virtual ~A() {} virtual void some_func(const unsigned int& param1, const char*) { some_func(param1); } }; class B : public A { p...

How to hide the constructor and "general" functions from individual objects?

I'm looking for advice on the best way to structure my program. Here is what I have now, and the problems I see with the design: I have a class with a private constructor and a submit() method, to carefully control the objects created, and every object created is added to a global list. The program has several functions that perform "bi...

how to proper delete pointer to array

Hi, I'm new to C++, and im confused about arrays and pointer. Could someone tell me how can i properly delete a pointer. Like for example, int *foo; foo = new int[10]; delete foo; or delete [] foo; Thanks. ...

Calling WinSock functions using LoadLibrary and GetProcAddress

Basically I have a header file like this: #if WIN32 typedef DWORD (WSAAPI *SocketStartup) (WORD wVersionRequested, LPWSADATA lpWSAData); typedef SOCKET (WINAPI *MakeSocket)(IN int af, IN int type, IN int protocol, IN LPWSAPROTOCOL_INFOW lpProtocolInfo, IN GROUP g, IN DWORD dwFlags ); typedef DWORD (WINAPI *SocketSendFu...

Why use an object instance rather than class::staticFunction?

Why should I use an object instance to access member functions rather than class::staticFunction? ( or why not? ) ...

Strange VC++ compile error, C2244

Take a look at this peice of code: template <typename K,typename T> Pointer<typename Collection<T>::Iterator> BinaryTree<K,T>::GetBeginning() const { return new BinaryTreeIterator(this,BinaryTreeIterator::Position::atBeginning); } When I try to compile it using VSTS 2008, I get: error C2244: 'BinaryTree<K,T>::GetBeginning' : unab...