I'm trying to achieve the following optimization in my container library:
when inserting an lvalue-referenced element, copy it to internal storage;
but when inserting rvalue-referenced element, move it if supported.
The optimization is supposed to be useful e.g. if contained element type is something like std::vector, where moving if...
A naive question - i am a novice on mac programming.
How to change text color on Macintosh? My code uses TESetText and TEUpdate for drawing.
PS - Mac is really really badly documented.
...
Why does cout has to be flushed before cin starts reading? Aren't they of different buffer? I can have reading of input into a buffer while same time putting it on output buffer (before flushing) .. 2 different buffers. I am confused here.
...
I've been a PHP programmer for 8 or so years, I'm familiar with OOP and try to consider best practices whenever programming. I would like to pick up C++ to possibly enter the 'game development' field, where now I'm doing web dev.
I'm not a school person, but was wondering what people think about self-taught math to complement learning ...
I am running QT Creator on a Linux Ubuntu 9.10 machine. I just got started with QT Creator, and I was going through the tutorials when this error popped up while I was trying to build my project: "ISO C++ forbids declaration of 'QPushButton' with no type". This problem appears in my header file:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H...
Recently, I was buzzed by the following problem STL std::string class causes crashes and memory corruption on multi-processor machines while using VC6.
I plan to use an alternative STL libraries instead of the one provided by VC6.
I came across 2 libraries : STLPort and SGI STL
I was wondering what is the difference between the 2. Whi...
i have a txt file which have some lines ...and my code is :
string line;
ifstream myfile("c:\\main.txt");
bool passport = true;
while(passport==true){
int pos1=0;
cout<<setw(20)<<"PassPort_Number : ";
cin>>add.Id ;
if (myfile.is_open())
{
while(!myfile.eof()){
getline(myfile,line);
...
I have a little problem that involves modeling a state machine.
I have managed to do a little bit of knowledge engineering and 'reverse engineer' a set of primitive deterministic rules that determine state as well as state transitions.
I would like to know what the best practices are regarding:
How to rigorously test my states and st...
Writing an app that will include the ability to decompress zip and rar files. I think I'm OK on how to handle the .zips but .rars seem a little more trouble. I noticed that rarlabs has source available but it's C++. Is there a way to compile, wrap or otherwise use this code within an iPhone app?
Reference: http://www.rarlab.com/rar_add....
Hi,
I am a C++ beginner. I have the following code, the reult is not what I expect. The question is why, resp. what is wrong. For sure, the most of you see it at the first glance.
struct Complex {
float imag;
float real;
Complex( float i, float r) {
imag = i;
real = r;
}
Complex( float r) {
Co...
I have a C# COM server which is consumed by a cpp client.
One of the C# methods returns a string.
In cpp the returned string is represented in Unicode (UTF-16), at least according to the memory view.
Is this always the case with COM strings?
Is there a way to use UTF-8 instead?
I saw some code where strings were passed between cpp an...
I can have
std::bitset< 10 > bitsetA;
or
const size_t LengthB = 20;
std::bitset< LengthB > bitsetB;
without any problem.
But, if the length is not const
size_t LengthC = 30;
std::bitset< LengthC > bitsetC; // Line 30, say
I face the following compilation error
'LengthC' cannot appear in a constant-expression
template arg...
Regarding the terminate handler,
As i understand it, when something bad happens in code, for example when we dont catch an exception,
terminate() is called, which in turn calls abort()
set_terminate(my_function) allows us to get terminate() to call a user specified function my_terminate.
my question is: where do these functions "live...
How do I set up gdb on window so that it does not allow a program with assertion failure to terminate? I intend to check the stack trace and variables in the program.
For example, running this test.cpp program compiled with MinGW 'g++ -g test.cpp -o test' in gdb:
#include <cassert>
int main(int argc, char ** argv) { assert(1==2); retu...
1>Project : error PRJ0003 : Error spawning 'rc.exe'.. this is the error i get when i try to run this small practice program of reading and writing files which i cant do because of the reason of me not being able to get the files to open correctly. i use microsoft visual c++ 2008 and i have used the file path to try to open the file as w...
Does the runtime library pollute the global namespace?
...
The following does not work and gives me a SIGABRT when I run in the debugger:
std::ifstream inFile;
inFile.open("/Users/fernandonewyork/inputText.txt");
cout << inFile << endl;
vector<string> inText;
if (inFile) {
string s4;
while (inFile>>s4) {
inText.push_back(s4);
}
}
inFile.close();
The following...
Will the following piece of code work as expected in a multi-threaded scenario?
int getUniqueID()
{
static int ID=0;
return ++ID;
}
It's not necessary that the IDs to be contiguous - even if it skips a value, it's fine.
Can it be said that when this function returns, the value returned will be unique across all threa...
Thought it was pretty straight forward.
But I get a "iterator not dereferencable" errro when running the below code.
What's wrong?
template<typename T>
struct SumsTo : public std::binary_function<T, T, bool>
{
int myInt;
SumsTo(int a)
{
myInt = a;
}
bool operator()(const T& l, const T& r)
{
c...
Using the following code:
template <typename T>
class node {
[. . .]
};
class b_graph {
friend istream& operator>> (istream& in, b_graph& ingraph);
friend ostream& operator<< (ostream& out, b_graph& outgraph);
public:
[...]
private:
vector<node> vertices; //This line
I'm getting:
error: type/value mismatch at argument ...