Forum: C++ 21 Days Ago |
| Replies: 4 Views: 373 I'd guess that what's holding up the program is printing to the console output, which is a slow process. Try writing to a file instead and it'll probably help with speed. Then see if you need to... |
Forum: C++ 28 Days Ago |
| Replies: 9 Views: 403 You really should comment your code.
And on a side note check out cin.ignore(); after cin>>'ing. |
Forum: C++ 30 Days Ago |
| Replies: 9 Views: 525 |
Forum: C++ 31 Days Ago |
| Replies: 6 Views: 349 |
Forum: C++ 34 Days Ago |
| Replies: 11 Views: 546 >> sizeof( any pointer ) is always the same
>> That happens to be true for the garden variety PC of today, but it is not true as a generic statement.
Also, on the same system fat pointers are... |
Forum: C++ Oct 16th, 2009 |
| Replies: 3 Views: 524 All that changes with iterators that aren't 'int's is the template argument. http://www.cplusplus.com/reference/stl/vector/erase/
std::vector<randomType> myVec;
// Fill the vector with something... |
Forum: C++ Aug 12th, 2009 |
| Replies: 3 Views: 363 Someone asked something similar before in another forum (http://cboard.cprogramming.com/cplusplus-programming/107469-custom-loose-coupling-string.html) and you could do something like this.class... |
Forum: C++ Aug 10th, 2009 |
| Replies: 2 Views: 483 You could have it so the constructor requires a flag to ID the allocated item... so something like...class base {
public:
enum derrivableIDs {
idBase,
idOne,
idTwo
};
... |
Forum: C++ Aug 8th, 2009 |
| Replies: 6 Views: 345 Curious. You should use std::strings really...std::string strItoA(int number) {
std::ostringstream sin;
sin << number;
return sin.str();
}Though Narue may tell you to generalise... |
Forum: C++ Jul 19th, 2009 |
| Replies: 5 Views: 409 http://www.codeguru.com/forum/showthread.php?t=302806
First hit on google.
Basically, it extracts segments from a varaible, i.e. the higher or lower 16 bits. |
Forum: C++ Jul 19th, 2009 |
| Replies: 14 Views: 613 You should read about getline here, http://www.cplusplus.com/reference/iostream/istream/getline/
Personally, I'd use std::string-s and getline... #include <string>
#include <fstream>
#include... |
Forum: C++ May 3rd, 2009 |
| Replies: 5 Views: 339 Nah. You'll probably have to specialise the template, I'd say. Or overload a > operator, if you feel like it. |
Forum: C++ May 2nd, 2009 |
| Replies: 2 Views: 919 You can do what's called 'template specialisation' which will implement certain functions for a specific type, basically.
template<typename ty>
class myClass {
private:
ty var;
public:
... |
Forum: C++ May 2nd, 2009 |
| Replies: 4 Views: 516 Nope.
class thing {
private:
std::string str;
public:
thing(std::string _str)
: str(_str) {
}
std::string &getAttribute() { |
Forum: C++ May 2nd, 2009 |
| Replies: 4 Views: 516 aa is a pointer so you have to either dynamically allocate an instance of a, or set it to the address of an already instantiated instance, and call aa->getAttribute();. Alternatively doaa a;... |
Forum: C++ Nov 22nd, 2008 |
| Replies: 12 Views: 1,372 Well, there are two common ways you can represent complex numbers. One is a+ib where i is the root of -1, which is NOT -1. This is called the Cartesian (or rectangular) coordinate system. The second... |
Forum: C++ Oct 15th, 2008 |
| Replies: 3 Views: 904 goto (http://xkcd.com/292/) |
Forum: C++ Oct 11th, 2008 |
| Replies: 11 Views: 1,534 I think you might have to return a reference/pointer to the stream. Though if it's a local variable you might have to return a dynamically allocated stream. |
Forum: C++ Oct 1st, 2008 |
| Replies: 7 Views: 1,631 >> Gee, what more do you want?
A clickable link would be nice. I don't want to have to copy and paste again, Salem! |
Forum: C++ Sep 29th, 2008 |
| Replies: 5 Views: 445 Because they do input or output. One could say the same about your FileHandler class. Meh. If you're only gonna be reading use ifstream, only writing use ofstream, if you're gonna be doing both use... |
Forum: C++ Sep 29th, 2008 |
| Replies: 5 Views: 445 If you use fstream you can both read and write to the strem. http://www.cplusplus.com/reference/iostream/fstream/ To be honest, I don't see the point in reinventing the wheel, but what the hey. Why... |
Forum: C++ Sep 28th, 2008 |
| Replies: 13 Views: 1,063 I made one list (mylist *l) and added an element to it (l->next = new mylist;), then compared items in the same list (iter->num > iter->next->num). iter is simply a pointer which points to the... |
Forum: C++ Sep 28th, 2008 |
| Replies: 13 Views: 1,063 Here's a very crude example which I haven't tested, but even if it doesn't work it'll show you how to go about the problem...struct mylist {
int num;
mylist *next;
};
int main( void ) {
... |
Forum: C++ Sep 28th, 2008 |
| Replies: 13 Views: 1,063 Maybe something like:nodo *p1, *p2;
p1 = List;
p2 = List->next;
if ( p1->key == p2->key ) // or p1->key == p1->next->key
// do this...Your problem is that you don't have a random access... |
Forum: C++ Sep 25th, 2008 |
| Replies: 4 Views: 633 In my opinion without some careful management it's asking for trouble. Why do you have to open it? Couldn't you do something like...std::[i/o]fstream fstr;
// ...
fstr.open( "file_name" );... |
Forum: C++ Sep 22nd, 2008 |
| Replies: 10 Views: 924 To understand the reasoning of this execute the following:int main() {
std::cout<< sizeof( unsigned long) << ", " << sizeof( unsigned short ) ;
return 0;
}Basically short*short = short, but... |
Forum: C++ Sep 14th, 2008 |
| Replies: 6 Views: 1,554 #include <iostream>
#include <vector>
int main( void ) {
// 4x5 (4 in x, 5 in y) array, containing -1
std::vector< std::vector<int> > vvint( 5, std::vector<int>( 4, -1 ) );
for( int... |
Forum: C++ May 29th, 2008 |
| Replies: 6 Views: 957 So it'll say like 13 and you want to grab the next 13 characters? Will the length actually be wrapped in []? If ya have boost installed use boost::regex for the simplest way. You might be able to use... |
Forum: C++ May 9th, 2008 |
| Replies: 3 Views: 430 Maybe try a:
void printMe const {
// Code here...
} |
Forum: C++ May 8th, 2008 |
| Replies: 3 Views: 1,316 |
Forum: C++ May 6th, 2008 |
| Replies: 5 Views: 561 Why do you need to cast or even make a and b? Just test num1 and num2:using namespace std;
int main()
{
while(1)
{
int num1, num2;
cout << "Insert two numbers" <<... |
Forum: C++ Feb 28th, 2008 |
| Replies: 5 Views: 686 Change:
if (guess< number, tries++)
to
tries++;
if (guess< number)
// ...
else if (guess>number )
//...You should only need to increment tries once. |
Forum: C++ Feb 28th, 2008 |
| Replies: 5 Views: 686 <iostream.h>, <stdlib.h> and <time.h> should not be used. Use instead <iostream>, <cstdlib>, and <ctime> In terms of <iostream.h> ... it's old. <iostream> is new and good. The other two are used in... |
Forum: C++ Feb 26th, 2008 |
| Replies: 3 Views: 687 Probably. That's the way I do it. You can also, if you wish, look into LoadLibrary (capitalisation?). |
Forum: C++ Feb 26th, 2008 |
| Replies: 3 Views: 687 #include <my_dll.h>
#pragma comment( lib, "my_dll.lib" )
int main() {
my_dll_function();
return 0;
}Should work with your IDE. |
Forum: C++ Jan 28th, 2008 |
| Replies: 9 Views: 952 Well, as nice as command != ('A' || 'B') looks it doesn't work like that. if( command != 'A' || command != 'B' ) is what you're looking for, but to be honest a straight out else should do -- it's... |
Forum: C++ Jan 26th, 2008 |
| Replies: 16 Views: 3,373 >> Could anybody help me with the code please?
Not unless you show some work.
But it's not that hard. There are two problems to overcome -- 1) filling the array 2) reading values from a file. Once... |
Forum: C++ Jan 9th, 2008 |
| Replies: 4 Views: 1,793 I really don't know what you mean. Do you want to save integers to file? Binder? |
Forum: C++ Jan 1st, 2008 |
| Replies: 10 Views: 1,277 I'm pretty sure you're making that up, or at least mistaking it.
Do you have a cin.ignore() or cin.get() or something before the function is called?
Also, you should use std::string to read in... |
Forum: C++ Nov 19th, 2007 |
| Replies: 4 Views: 1,973 One thing you could do is map out a directory. The structure could have the name of the directory, an array of sub-directories (which would possibly be a pointer to a new instance of the structure... |