c++

do you do the following operations in C++?

Hi all, how do you do the following operations in C++? Opening Files Closing Files Reading Files Writing Files ...

Scope and return values in C++

Hey!! I am starting again with c++ and was thinking about the scope of variables. If I have a variable inside a function and then I return that variable will the variable not be "dead" when it's returned because the scope it was in has ended? I have tried this with a function returning a string and it did work. Can anyone explain this?...

When would I use uncaught_exception?

What is a good use case for uncaught_exception? ...

C++ Reading file Tokens

Hi, another request sorry.. Right now I am reading the tokens in one by one and it works, but I want to know when there is a new line.. if my file contains Hey Bob Now should give me Hey Bob [NEW LINE] NOW Is there a way to do this without using getline? ...

Inspecting STL containers in XCode

From googling around it looks like XCode (3.1 in my case) should be at least trying to give me a sane debug view of STL containers - or at least vectors. However, whenever I go to look at a vector in the debugger I just see M_impl, with M_start and M_finish members (and a couple of others) - but nothing in-between! (it's a debug build, ...

Splitting String C++

Hi in C++ if i have a string, how can I split this into tokens? ...

Conversion of Fortran 77 code to C++

Has anyone converted a large (ours is 550,000 lines) program of Fortran 77 code to C++ ? What pitfalls did you run into ? Was the conversion a success ? Did you use a tool like for_c ( http://www.cobalt-blue.com/fc/fcmain.htm ) ? Was the resulting C++ code significantly faster or slower ? ...

cout Formatting

Hi, I'm pretty sure this is a simple question in regards to formatting but here's what I want to accomplish: I want to output data onto the screen using cout. I want to output this in the form of a table format. What I mean by this is the columns and rows should be properly aligned. Example: Test 1 Test2 ...

Output ASCII Value C++

Hi, If I have a char which holds a hex value such has 0x53, (S), how can I display this as "S"? Code: char test = 0x53; cout << test << endl; Thanks! ...

How can I tokenize a C++ string?

Duplicate: How do I tokenize a string in C++? I have a character array in C++. arr="abc def ghi" I want to get the strings "abc" "def" "ghi" out of the string. Are there any built in functions to do this? ...

Is it more efficient to return a const reference

E.g. What's best out of these: std::string f() {} or const std::string& f() {} ...

acceptable fix for majority of signed/unsigned warnings?

I myself am convinced that in a project I'm working on signed integers are the best choice in the majority of cases, even though the value contained within can never be negative. (Simpler reverse for loops, less chance for bugs, etc., in particular for integers which can only hold values between 0 and, say, 20, anyway.) The majority of ...

How to overcome GCC restriction "could not convert template argument '0' to 'Foo*'"?

Suppose I have code like this: template<class T, T initial_t> class Bar { // something } And then try to use it like this: Bar<Foo*, NULL> foo_and_bar_whatever_it_means_; GCC bails out with error (on the above line): could not convert template argument '0' to 'Foo*' I found this thread: http://gcc.gnu.org/ml/gcc-help/2007...

Most efficient way to list items in C/C++

I have a list of say 100 unsorted items. Each item belongs to a group. The group the item belongs to is simply a member of the item class. Using C/C++ I'm looking for the most efficient way of scanning through the list of items, checking which group they are in and printing the item to the screen. Here's the catch though. Once an item f...

What's the best way to do a backwards loop in C/C#/C++?

I need to move backwards through an array, so I have code like this: for (int i = myArray.Length - 1; i >= 0; i--) { // Do something myArray[i] = 42; } Is there a better way of doing this? Update: I was hoping that maybe C# had some built-in mechanism for this like: foreachbackwards (int i in myArray) { // so easy } Up...

std::wcout to console window in XCode

In an XCode project, if I use std::cout to write to the console the output is fine. However, if I use std::wcout I get no output. I know that this is a thorny issue in C++, and I've been googling around to try and find a specific solution in the XCode case. A couple of things I found that it was suggested should work were: std::c...

What is the optimal size of a UDP packet for maximum throughput?

I need to send packets from one host to another over a potentially lossy network. In order to minimize packet latency, I'm not considering TCP/IP. But, I wish to maximize the throughput uisng UDP. What should be the optimal size of UDP packet to use? Here are some of my considerations: The MTU size of the switches in the network is 15...

Better way to implement count_permutations?

I need a function count_permutations() that returns the number of permutations of a given range. Assuming that the range is allowed to be modified, and starts at the first permutation, I could naively implement this as repeated calls to next_permutation() as below: template<class Ret, class Iter> Ret count_permutations(Iter first, Iter ...

C++ converting a mac id string into an array of uint8_t

I want to read a mac id from command line and convert it to an array of uint8_t values to use it in a struct. i can not get it to work. i have a vector of string for the mac id split about : and i want to use stringstream to convert them with no luck. can anyone point me what i am missing? int parseHex(const string &num){ stringstre...

Catching all unhandled C++ exceptions?

Is there some way to catch exceptions which are otherwise unhandled (including those thrown outside the catch block)? I'm not really concerned about all the normal cleanup stuff done with exceptions, just that I can catch it, write it to log/notify the user and exit the program, since the exceptions in these casese are generaly fatal, u...