I have a simple data file that I want to load, in a C++ program. For weird reasons, it doesn't work:
I tried it on Windows assuming the file was in the same directory: failed.
I tried it on Windows by moving the file in C:\ directory: worked.
I tried it on Linux putting the file in the same directory: failed.
The snippet:
void World...
Possible Duplicate:
Calling virtual functions inside constructors
first of all below code is not working visual c++ , but workin with bloodshed
output is 0 , but acc. to me it shud be 1 ; can anyone explain this
#include<iostream>
using namespace std;
class shape
{
public:
virtual void print() const =0;
virtual double...
Is it recommed to put a while loop, which never ends in a constructor? Or should I use threads to get the same result?
Is it good when a constructor never terminates? Or is it more secure to avoid segmentation faults?
Hope you understand my bad English..
...
I need to concatenate two const chars like these:
const char *one = "Hello ";
const char *two = "World";
How might I go about doing that?
I am passed these char*s from a third-party library with a C interface so I can't simply use std::string instead.
...
I have an OpenGL-program using GLSL, that I can run just fine with the Play-button in Visual Studio (2008) -- both in the standard Release and Debug configurations.
However, when I try to run the executable from Explorer, all I get is a flashing cmd-prompt with no text in it to indicate any kind of failure loading something.
I have tri...
string::iterator it;
for (it = str.begin(); it < str.end(); it++)
cout << *it;
cout << endl;
Why not:
for (int i = 0; i < str.size(); i++)
cout << str[i];
cout << endl;
It seems that string::iterator does not provide range check either. Why should we use string::iterator rather than index?
Thanks.
...
I have the following class:
GLRectangle.h
#include "XPView.h"
class GLRectangle
{
public:
int top, left, bottom, right;
public:
GLRectangle(void);
~GLRectangle(void);
GLRectangle* centerRect(int rectWidth, int rectHeight, int boundWidth=0, int boundHeight=0);
};
GLRectangle.cpp
#include "GLRectangle.h"
GLRectangle...
hi!
templates allow in c++ to automatically create a lot of classes with the same interface, but different data stored.
i'm looking for something similar (i don't know whether it exists, that's why I ask here) that automatically creates for me variations of an object storing only a subset of the datamembers.
let's say i have a
class ...
template<class T>
void swap(T &a, T &b)
{
T t;
t = a;
a = b;
b = t;
}
replace
void swap(int &a, int &b)
{
int t;
t = a;
a = b;
b = t;
}
This is the simplest example I could come up with,but there should be many other complicated functions.Should I make all methods I write templated if possible?
An...
Hi, I want to make chat application and for the first step, I need to know which API there is to use to display text in lines and also erase if needed. thanks!
...
void permute(string elems, int mid, int end)
{
static int count;
if (mid == end) {
cout << ++count << " : " << elems << endl;
return ;
}
else {
for (int i = mid; i <= end; i++) {
swap(elems, mid, i);
permute(elems, mid + 1, end);
swap(elems, mid, i);
}
}
...
The more I hear and read about C++ (e.g. this: http://lwn.net/Articles/249460/), I get the impression, that I'd waste my time learning C++. I some wrote network routing algorithm in C++ for a simulator, and it was a pain (as expected, especially coming from a perl/python/Java background ...).
I'm never happy about giving up on some tec...
What are static variables designed for? What's the difference between static int and int?
...
I am trying to figure out why when I convert my main.m file to a main.mm file, it no longer will link properly.
I have reduces the problem to the following example code:
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
int main( int argc, const char ** argv ) {
return NSApplicationMain( argc, argv);
}
I am using gnustep an...
I've given this a lot of thought but haven't really been able to come up with something.
Suppose I want a m X n collection of elements sortable by any column and any row in under O(m*n), and also the ability to insert or delete a row in O(m+n) or less... is it possible?
What I've come up with is a linked-grid, where the nodes are inser...
How is division calculated on compiler/chip level?
And why does C++ always throw these exceptions at run-time instead of compile-time (in case the divisor is known to be zero at compile time)?
...
Just about everyone uses them, but many, including me simply take it for granted that they just work.
I am looking for high-quality material. Languages I use are: Java, C, C#, Python, C++, so these are of most interest to me.
Now, C++ is probably a good place to start since you can throw anything in that language.
Also, C is close to...
I'm trying to pass a member function as an argument. Basically I have a class called AboutWindow, and the header looks as this (trimmed for brevity):
class AboutWindow
{
private:
AboutWindow(void);
~AboutWindow(void);
public:
int AboutWindowCallback(XPWidgetMessage inMessage, XPWidgetID inWidget, long inParam1, long inParam...
Hi,
I am trying to write an application which amongst other things uses the openssl blowfish implementation (blowfish.h) to transport files over a simple server/client pair.
However, whilst some files are encrypted, transported, received and decrypted correctly, some end up being corrupted, after the final decryption stage. This lead...
In mathematics the identity (1 + sqrt(2))^2 = 3 + 2*sqrt(2) holds true. But in floating point (IEEE 754, using single precision i.e. 32 bits) calculations it's not the case, as sqrt(2) doesn't have an exact representation in binary.
So does using a approximated value of sqrt(2) provide different results for left and right hand sides? I...