Unimportant 18 Junior Poster

I just did it for you, what do you mean?

Oh, read my edit sorry.

I said the switch would be faster even if it encompassed every case.

letter='F' should be the default case, mind you.

Unimportant 18 Junior Poster

I really don't think what you want here is a switch, it would make sense in the ruby language, but C/C++ switch statements only accept constants:

switch( sum ) {
   case 100:
   case 99:
   // ... // yes you have to write them all
   case 96:
     letter='A';
     break;
   case 95:
   ...
   case 86:
     //
     break;
   default:
     letter='F';
     break;
}

The switch can cascade (note that I didn't break unless I reached a letter), but I think you'll actually get a slower speed than the simple boolean evaluation you are doing.

Good luck!

Edit: I changed my mind.
This switch statement will be faster than your code.
The reason is because a switch uses the constant as an offset to function pointer (linear access time), so no evaluation is done.
I think for any if-else chain of 3 length or greater, a switch will be faster if a switch is possible. (in C/C++ at least)
If that's questionable you'll have to look up the optimization in your native compiler, I have no intention of doing so. Feel free to correct me if you do this and I was wrong though!

kra9853 commented: Great help +1
Unimportant 18 Junior Poster

I don't know about 2003, I use 2008.
I've never had a problem with std::fstream (fstream is both in and out)

What is the error you are getting?

Unimportant 18 Junior Poster

PlaySound("file.wav",NULL,SND_FILENAME|SND_ASYNC);

Note the flag SND_ASYNC, which means that the file will play asynchronously during process execution (it won't block). So if you set this flag, it will play the file without 'pausing'

Unimportant 18 Junior Poster

You might be interested in std::fstream, but do whatever way is easiest for you.

Unimportant 18 Junior Poster

Just a little proof of concept, unrefined example of modifying base 2 to base 10

#define bin_1    (1<<0)
#define bin_2    (1<<1)
#define bin_4    (1<<2)
#define bin_8    (1<<3)
#define bin_16   (1<<4)
#define bin_32   (1<<5)
#define bin_64   (1<<6)
#define bin_128  (1<<7)
unsigned char a = 219;
double dig_1(0), dig_2(0), dig_3(0);
if( a & bin_128 ) {
  dig_3 = 1.28;
  dig_2 = 2.8;
  dig_1 = 8;
}
if( a & bin_64 ) {
  dig_3 += 0.64;
  dig_2 += 6.4;
  dig_1 += 4;
  if( dig_1 > 10 ) dig_1 -= 10;
}
if( a & bin_32 ) {
  dig_3 += 0.32;
  dig_2 += 3.2;
  dig_1 += 2;
  if( dig_3 > 10 ) dig_3 -= 10;
  if( dig_2 > 10 ) dig_2 -= 10;
  if( dig_1 > 10 ) dig_1 -= 10;
}
if( a & bin_16 ) {
  dig_3 += 0.16;
  dig_2 += 1.6;
  dig_1 += 6;
  if( dig_3 > 10 ) dig_3 -= 10;
  if( dig_2 > 10 ) dig_2 -= 10;
  if( dig_1 > 10 ) dig_1 -= 10;
}
if( a & bin_8 ) {
  dig_3 += 0.08;
  dig_2 += 0.8;
  dig_1 += 8;
  if( dig_3 > 10 ) dig_3 -= 10;
  if( dig_2 > 10 ) dig_2 -= 10;
  if( dig_1 > 10 ) dig_1 -= 10;
}
if( a & bin_4 ) {
  dig_3 += 0.04;
  dig_2 += 0.4;
  dig_1 += 4;
  if( dig_3 > 10 ) dig_3 -= 10;
  if( dig_2 > 10 ) dig_2 -= 10;
  if( dig_1 > 10 ) dig_1 -= 10;
}
if( …
Unimportant 18 Junior Poster

Powers of 10? Assuming you want a decimal representation.

You'll have to define 'digit', due to this ambiguity.
0xFF vs 255, 2 'digits' vs 3

Unimportant 18 Junior Poster

Oh just a side note, but I wouldn't use your approach at all:

return low+int((high-low+1)*rand()/(RAND_MAX+1.0));

but that's just me

What I mean is, why aren't you just offsetting your range once you already have an element of the subset selected?

Unimportant 18 Junior Poster

instead of using parameters like this:
int foo( int min, int max );

why not:

int range_rand( int a, int b ) {
  int high, low;
  (a<=b)?(low=a,high=b):(low=b,high=a);
  int ans=rand()%high; // I'm assuming you seeded rand already
  if( ans < low ) ans+=low; // this won't actually work if your range is too small, so you'll need to give some thought to this line
  // such as adding the difference between high and low (as rand()%(high-low)), instead of low, and adding it to ans until ans is >= low
  return ans;
}
Unimportant 18 Junior Poster

For std::string, I'd do it this way:

// case insensitive string compare function
int compare_string(const std::string & s1, const std::string& s2) {
    std::string::const_iterator it1=s1.begin();
    std::string::const_iterator it2=s2.begin();

    size_t size1=s1.size(), size2=s2.size();// cache lengths
    //return -1 or 1 according to strings' lengths
    if (size1!=size2) 
        return (size1<size2) ? -1 : 1;
    //stop when either string's end has been reached
    while ( (it1!=s1.end()) && (it2!=s2.end()) ) { 
        if(::toupper(*it1) != ::toupper(*it2)) // letters differ?
            // return -1 to indicate smaller than, 1 otherwise
            return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1; 
        //proceed to the next character in each string
        ++it1;
        ++it2;
    }
    return 0; // sizes and values equivalent
}

You'll have to modify it a little bit to accommodate an array of char

Good luck!

Unimportant 18 Junior Poster
while (num == 0) {
cout << "Type in two values:\n";
cin >> num; // num isn't 0 if you enter anything but 0, no more while loop.

You said "keep looping", obviously it won't loop if num isn't 0

If you want it to loop forever, try doing this:
while(true) {
}

Then it will never end.

That's kind of bad though, so you should just use an exit value.

char input('a');
while( input != 'n' ) {
  std::cout << "Type n to quit.";
  std::cin >> input;
}

Edit: Oops, I lied. You put num=0; at the end.
What do you mean by keep looping?
Do you want the min/max of every value you've ever entered (not just 2 values)?
If so you'll need an array to store the data.

Unimportant 18 Junior Poster
// use a template class
template <typename T, typename T2> class DataCompare {
public: // you can probably do this better, I just directly modified your example
// It probably won't suit your needs, etc etc, might have typos
  bool operator()(const T& el1, const T& el2) const {
    return lessK(el1.first, el2.first);
  }
  bool operator() (const T2& el1, const T& k) const {
    return lessK(el1.first, k);
  }
  bool operator ()(const T& k, const Data& T2) const {
    return lessK(k, el2.first);
  }
private: // I was really lazy about this part because it's an example
  bool lessK(const T& k1, const T2& k2) const {
    return k1 < k2;
  }
  bool lessK(const T2& k1, const T& k2) const {
    return k1 < k2;
  }
  bool lessK(const T2& k1, const T2& k2) const {
    return k1 < k2;
  }
  bool lessK(const T& k1, const T& k2) const {
    return k1 < k2;
  }
};

Just a push in the right direction, good luck!

Edit: After looking it over, you can probably just do this

template <typename T, typename T2> class DataCompare {
public:
  bool operator()(const T& el1, const T& el2) const {
    return el1.first < el2.first;
  }
  bool operator() (const T& el1, const T2& k) const {
    return el1.first < k;
  }
  bool operator ()(const T2& k, const T2& k2) const {
    return k < el2.first;
  }
};

As long as the < operator is overloaded.

Unimportant 18 Junior Poster

No, I told you from the start, this line of code is just wrong:
comptr pc[1] = pc[0]; // You can't do this.

Your compiler is telling you that's impossible.

pc[1] is already comptr
you are making it comptr "again"
comptr pc[1] <--- is bad because:
comptr *pc = new comptr[50]; // range 0 - 49, --> this is 50 comptr objects

This code also works:

comptr *pc; // note no new yet
pc = new comptr[50]; // there are 50 comptr objects now
// *pc is not a computer, it is a -pointer-
// it points to the beginning of the array (&comptr[0])
// pc[1] means, &comptr[0] + size in bytes of comptr (&comptr[1])

// so when you do this
pc[0].defaultinfo();
pc[1] = pc[0];
pc[2] = pc[1];
pc[3] = pc[0];

// all objects from pc[0] to pc[3] are equal to the value of pc[0]
// they are separate objects
pc[1].defaultinfo(); // now you can change pc[1]
// pc[0], pc[2], and pc[3] are still the same, they are their own object

comptr pc[4]; // ERROR. YOU ALREADY DEFINED PC[4], it is a comptr object -already-

You said:
"i think there is no way to get array1 objects specific items and put into array 2 objects."
and that's wrong, I am showing you how to do that.

Unimportant 18 Junior Poster

char **name;
means you initialize a variable which is a pointer to a pointer to char.

any array is a pointer, the value in the [] operator is an offset.

char array[5]; is a table of 5 characters, array[3] is the address of array[0] + 0x03

char *a; // this is creating a pointer to char
a = new char[5]; // this allocates 5 bytes into heap memory, a is now the address of the first byte (a is effectively &char[0])

char **a; // this means that a points to an array of arrays. remember that an array is a pointer in the first place.

I think the wordiness is confusing.

Basically **name means that *name points to an array, and **name points to an array of *name (forgive the loose use of this variable name please)

Hope that clears up any misunderstanding you might have about that.

As for the keyword new, it just means that you're allocating heap memory.
You could delete the array and make a new one at any time, it is by this process that STL classes such as std::vector automatically resize themselves during run time.

Good luck!

Edit: Oh also, if you're allowed to use STL, it's way easier to do this:

std::vector<std::string> names;
names.push_back( any_string );

It will grow for you, without any additional code required. std::string is also very easy to use.

Unimportant 18 Junior Poster

char[25] can only hold '1' string of 25 character length, each character is 1 byte of data (char)

for example, this isn't dynamic or anything, but if you did this:
char[25][15] you could store 25 names, which are up to 15 characters long

name will be able to hold only 1 letter, so I don't think that's what you want.


// allocate memory
  char **name = new char*[num_strings];
  for (int i = 0; i < num_strings; ++i)
    name[i] = new char[15];

// Edited some weird mistakes in my thought process...

You also have a problem with cin, since you want to use an array of char, you'll need to address it like this:
std::cin >> name; // BEFORE you say this is the same as what you are doing, it isn't. It's different because in my example, name is 2D array ( name[25][15] )

In the example you gave, you should have done this:
std::cin >> name; // full stop
But then you would only have 1 name

Good luck!

Edit: Oh, you have to iterate to delete if you do it like this also. Worth mentioning probably.

// de-allocate memory
  for (int i = 0; i < num_strings; ++i)
    delete [] name[i];
  delete [] name; // note that i iterate first in this example, and then delete the base array -after-, reverse of original example
Unimportant 18 Junior Poster

Haha, I wasn't compiling it at all. That's basically a typo and is the same thing that I'm pointing out in the first place.... "It's out of bounds because you didn't allocate that much", which is what I said in my first post.

Unimportant 18 Junior Poster

I just explained this to you above.

word.at(i) = word.at(j); <-- you are changing the value of word

The reason I changed it to test for you, is because you aren't changing test.
When you output the contents of your test variable, it will be the same as when you set test equal to the value of word.

Basically, "word" is the only thing you are changing.

I also pointed out, that while you are changing it, you're also reading from the changed variable.

word.at(i) = word.at(j)
if i is 0, and j is 4
your word is attat

a = t

the word is now:
tttat

a = t

the word is now
tatat

You changed word.

You didn't reverse anything.

I specifically changed word.at(j) to test.at(j) because test is not being changed.


Edit: Here is a graphical example

std::string word("attat")
word[0] == a;
word[1] == t;
word[2] == t;
word[3] == a;
word[4] == t;

word[0] = word[4]; // <-- what did you expect? Why is it surprising that word changes when you personally change it
word[0] == t; // this now contains whatever character was in word[4]
word[1] == t;
word[2] == t;
word[3] == a;
word[4] == t;

word[0] = test[4];
word[0] == t; // this is the last letter of test, but
test[0] …
Unimportant 18 Junior Poster

word.at(i) = test.at(j);
compare to:
word.at( i ) = word.at( j ); // did you really want to write into what you're copying from?

As for your warning:
j = ( word.size() -1 );
j is an int, size() returns a size_t, which is an unsigned int
In this case, you can ignore the warning

the < is for the same reason, i < word.size() (int<unsigned int)
You won't be having any 2.1 billion character words, so you don't have to be concerned. The compiler doesn't know that, so it's warning you.

Unimportant 18 Junior Poster

An array has a size, you aren't properly defining your array size:

int r=0;
double array[r][1]; // this is a declaration

Change that to this:

int r=0; // int r(0); is also ok
double array[20][1]; // this allocates space for 40 doubles

Your while loop is redundant, just delete it.

double values[20][1]; // I renamed this because I think naming it array might be
// confusing you, sorry if that sounds condescending, it isn't meant to be.
// arrays are declared like this:
// class name[size];
// where class is any class/struct/primitive, whether it's "int" "double" or a user defined class
// the size is the maximum number of things that can appear in that array
// the last element is out of bounds, and arrays start from the 0th element

for( r=0; r<20; ++r ) { // this will count from 0 to 19, 20 is out of bounds
  values[r][0] = tf;
  values[r][1] = tf * (5/9) -32;
  tf+=5;
  // don't increment r here, you did it in the for loop already
}

Hope that helps!

Unimportant 18 Junior Poster

double array[r][1]; <--- r is 0, so this is the same as writing:
double array[0][1];

You then go on to increment r:
for(int r=0;r<20;r++) {

and try to write out of array bounds:
array[r][0] = tf;

but the array only goes up to array[0], not array[1].

Unimportant 18 Junior Poster

No no, you already did it.

cmptr(cmptr &p)
{
  name = p.name;
  agp = p.agp;
  lcd = p.lcd;
}

The code above is from your code.

constructors are defined like this:

classname( args ) : class_initialization() { // post initialization code }
// in this case
cmptr( cmptr &p ) {
// means that if you construct this object with the address of this object as an argument, do whatever is where this comment is
}
// so when you create an instance of the object like this
cmptr a(); // default constructor
cmptr OTHER(a); // copy constructor, OTHER is now constructed based on the constructor that accepts an address (or pointer to) another object of the same type
// when you invoke the assignment operator '=' and you have not defined an
// overload for assignment, by default the copy constructor is invoked if the
// type is the same.
// Here we have an assignment:
cmptr pc_a();
cmptr pc_b = pc_a;
// which invokes the copy constructor

Good luck!

Edit: I changed my mind. Based on what you are doing, the assignment overload is necessary, as pc[1] would be initialized already by the default constructor when you create it with new, as you did not pass any construction arguments.

cmptr & operator=( const cmptr p ) {
  name = p.name;
  agp = p.agp;
  lcd = p.lcd;
  return *this;
}

That's an example of how to overload your assignment operator.

Unimportant 18 Junior Poster

std::stringstream
std::fstream

vs

std::ostringstream
std::ofstream
std::ifstream
etc...

Edit: It seems I misunderstood your post, my apologies.
Personally, I'd do it the C way, because it would be easier for me. That's just my taste though, you should do whatever is easiest for you.

Unimportant 18 Junior Poster

You did not read my post.
You had a compiler error because you redefined the array:

cmptr pc[1]=pc[0]; // this is a redefinition

You defined the copy constructor yourself, so if you want it to do something different, then change it.

cmptr(cmptr &p)
	{
		name = p.name;
		agp = p.agp;
		lcd = p.lcd;
		
	}
// you didn't add most of the variables below
class cmptr
{
private:
	string rm;
	string hd;
	string nme;
	string agp;
	string mothrbrd;
	int lcd;
	int pcr;

...?

Unimportant 18 Junior Poster

std::map<std::string,dvd> car_info;

std::map will sort this array automatically based on the < operator for std::string

std::map["volvo"] = dvd(constructor values); // or whatever temporary dvd you make

Unimportant 18 Junior Poster
cmptr pc[1]=pc[0]; // this is a redefinition
pc[1] = pc[0]; // this is what you actually wanted, assuming a was at least 2

cmptr *pc = new cmptr[100]; // this would be a = 100
pc[0].defaultinfo(); // both totally ok
pc[99].defaultinfo(); // both totally ok
// pc is a pointer to memory segment containing 100 copies of the cmptr object in sequential order
// the number you pass to the [] operator is an "offset", which adds the size of an object in bytes to the address of pointer &array[0]
// so, &pc + 100 bytes might be pc[1] if each object is 100 bytes in memory, but this is kind of semantics

// hence:
cmptr pc[1]; // is totally wrong, you already gave pc[1] a definition.

// Edit: don't forget to delete the memory pc points to when you are done using it:
delete[] pc;

Good luck!

Unimportant 18 Junior Poster

last=MAX_UNSIGNED_INT?
Sounds like you subtracted 1 from 0, as there are not that many words in a dictionary.

Unimportant 18 Junior Poster

@sanchar
MSVC (MicroSoft Visual Studio) is just an IDE/compiler, "Visual C++" -is- C++, though I wouldn't say with complete certainty that it is 100% standards compliant, I think for your purposes it is effectively the same as "C++"

MSVC comes with a resource creator (for drag and drop creation of windows) which also allows you to easily modify the resource properties (such as names to use in message loop)

Good luck!

Unimportant 18 Junior Poster

Mathematical recursion is expressed with the capital sigma character, and I think what you mean is a self-addressing function. My misunderstanding.

void print(int a[], int n) {
  if(n==0)return; // a[0] is the first element, not a[1]
  std::cout<< a[--n] << " "; // print before calling this function again
  // the above line also has the effect of decrementing n by 1
  print(a, n); // this is called only if n wasn't 0
}

Good luck!

Edit: At some point you may want to print a newline (return character), to do this (in windows) just insert "\n" like so:
std::cout << "\n";

On that note, you might be interested in "escape characters", if you google that with quotes you will find plenty of documentation about them.

Unimportant 18 Junior Poster

Rather than predefining your array a[], why not use the integer value of n as the final output?

I don't like that you didn't post any code, but here's a hint:

for( i=0;i<n; ++i ) {
  a[i] = i+1;
  std::cout << a[i] << " ";
}
Unimportant 18 Junior Poster

Edit: You should remember that error message specifically, because it is a misleading one for less experienced programmers.

struct attrib{
char x;
int y;
char cont;
}; // <-- you didn't have a trailing semicolon
 
attrib brd[8][8]; //ERROR WAS HERE <-- no it wasn't
Unimportant 18 Junior Poster

Modify your for loop according to the values of n you want to iterate.

for numbers ranging from 10 to 10000:

for( i=10; i<10001; ++i ) {
}

would work just fine, so what's missing?

for( i=start; i<end+1; ++i ) {
}

just accept start and end as values from the user.

You can easily store each result from the for loop in an array, try using vector if you don't want to define a max size.

struct result_info {
  double i, x_i, y_curr;
  result_info(); // whatever constructor
  result_info( double a, double b, double c ) : i(a), x_i(b), y_curr(c) { }
}
std::vector<result_info> res;
res.push_back( result_info( i, x_i, y_curr ) );
output << res.back().i << " , " << res.back().x_i << " , " << res.back().y_curr << "\n";

Hope that helps, good luck!

raheel_88 commented: quick, concise response! many thanks +0
Unimportant 18 Junior Poster

This is what you posted

if(a!=0)
if((b==0) || (b!=0))
if((c==0) || (c!=0))

What this means is:
if A does not equal 0, execute: if B does not equal 0 OR if B DOES equal zero (no matter what): execute: if C equals or does not equal 0 (no matter what) execute:
// the rest of what you did

Basically all of your code is just dependent on whether or not a is 0, and the rest is totally off.

You don't know how to use if statements, nor do you know what logical operators do.

What you want is just this:

if( a != 0 || b != 0 || c != 0 ) { // if A OR B OR C are not equal to 0
  // do stuff
}

if statements will execute up to 1 line with no curly brackets, like so:

if(true) foo(); // calls foo()
if(true)
  foo(); // calls foo()
if(true)
if(false) { // is called if(true), but will never pass, whatever is inside of here will never execute
  std::cout << "*whispers* Hello World! ...sniffle" << std::endl;
}
Unimportant 18 Junior Poster

To access a single member of a string, it's typically safer to call string::at(), as it checks that the value passed to at() is in range.

substr() seems really round-about for getting just one character.
std::string[] or std::string.at() are much better solutions for your problem

In terms of processing an integer value into a roman numeral string, it might be better to use an order of magnitude consideration (power of 10), and perhaps an (if greater than 5), since all numerals are segmented as:
1 11 111 (sub 1)5 5

Including the upper range above 5.
The only thing that changes with each magnitude is the character represented.

That may, however, have been out of the scope of what you are doing.

Best of luck!

Unimportant 18 Junior Poster

Use the logical OR operator, which is "||" instead of "&&"

"&&" is the AND operator

(TRUE && FALSE && TRUE) evaluates to (FALSE)
(TRUE || FALSE || TRUE) evaluates to (TRUE)

Edit: A poster above me already mentioned this, but you should probably read up on the logical operators in general.

Unimportant 18 Junior Poster
template <class T>
T& foo(T &t) {
 // ;
}
template <class T>
T& foo(T &t, T &t2) {
 // ;
}

You may or may not be familiar with function pointers, but I'm going to use one as an example:

int foo(int x) { return x; }
int foo_caller(int (*foo)(int), int r) { return (*foo)(r); } // you can do fun stuff with void pointers here
int main() {
    void (*fptr)(int);
    fptr = foo;
    fptr(1);
    (*fptr)(2);
    foo_caller(fptr,x);
    return 0;
}

Now picture your compilers problem:
You want to pass a totally different kind of function.

I probably am about to go off on too much of a tangent, so I'm going cut it short.

Hope this was informative!

Unimportant 18 Junior Poster

Your problem is more related to the reason the limit system is a fundamental concept in calculus.

How many square sides do you need to create a perfect circle?
In this case, it's 1 per pixel.

How is that any less taxing than using a single trig function for each point in whatever granularity you specify?

If you don't care about accuracy, floating point computations are neither slow nor problematic with the right limitations. Not only that, but you could easily just do the math with an unsigned int type, flooring any decimal.

Unimportant 18 Junior Poster

Operators are just functions, the reason you cannot pass () and [] as the same argument is that they are not necessarily the same function, they have different memory addresses and associated methodology.

Rather, why not just overload your function?

void foo( int a ) { ; }
void foo( short a ) { ; }
Unimportant 18 Junior Poster

CreateThread()

Main is just the primary thread.

Edit: There are many implementations of createthread, and variations (such as createthreadex), an example implementation of createthread which might make your life easier is boost::thread

Unimportant 18 Junior Poster

Edit: Clarification.
'When' you call getLeafCount(node->right), is the stack value of 'node' the same as when the function began at first?
Short answer: No

int getLeafCount(struct node* node, int count) { 
  int temp = 0;
  if(node!=NULL) {
    if((node -> data %2) != 0) {
      temp++;
      count = count + temp;
    }
    getLeafCount(node->left, count);
    getLeafCount(node->right, count); // 'when' is this called?
  }
return count;
}

The important point here is that a function is just a memory address which reads values from the stack. Even after the function continues execution (after calling getleafcount from inside itself and returning), you've moved left a node, so reading node->right won't be the node you necessarily expect (the stack has changed).

I don't think what you wrote is necessarily the functionality you want.

Unimportant 18 Junior Poster

Sorry, I mentioned multimap for inserting equivalent elements, but mostly lost my train of thought in the explanation.

Also, please use code tags.

Try storing a struct instead of an int, example:

struct line_info {
  int line, count;
  line_info() : line(-1), count(-1) { }
  line_info( int a, int b ) : line(a), count(b) { }

  bool operator<(const line_info &ln) const {
    return this->line < ln.line;
  }
}

It's important to note that I overloaded the operator less than, because std::map uses less than to sort.

The issue with this approach is that it will only output each string one time, if you want to preserve the placement of each string, you'll need to add some complexity, such as including an array in the struct, and storing each line number separately.

Good luck!

Unimportant 18 Junior Poster

I'm not sure I believe you, but if you aren't sure where to start, you could start by reading the documentation on std::fstream

If you aren't allowed to use STL in your homework, read about these functions instead:
fscanf()
fgets()
fgetc()
fread()

Good luck! If you want more help you'll have to at least post an attempt to solve it yourself.

Unimportant 18 Junior Poster

What you are doing appears to be a text search, correct me if I am mistaken.

Why not read in a specific size at a time, such as 100MB. Make sure that the final character of your read is a space, or some other delimiter, as the exact size doesn't matter that much (in this case). Then, when you finish parsing that 100MB, rather than even deleting your array at all, just start writing to array[0] again (no need to reallocate necessarily). You could also just make the array static size in the first place (100MB + 1000 bytes to finish a word), it's usually faster to use stack memory, especially with large amounts of allocation.

Hope that helps

Unimportant 18 Junior Poster

Why not save each line as a string (whichever flavor you prefer), put those into any container/array, and then count them from there?

You could easily do it with a multimap<std::string,int> for example, where int is incremented for each equivalent std::string, or set to 1 if the element did not exist.
Then iterate through the map from map.begin(), and output the string (iterator->first), followed by however you would format the count (iterator->second)

Unimportant 18 Junior Poster

Hint: substr() and find()

Unimportant 18 Junior Poster

if(file.is_open()) // is a good place to start

Mind you, you may just not have enough RAM, especially with windows XP, to deal with a heap allocation of 1.5GB

Programs such as 7zip, which unzip files of greater sizes in XP, do so with partial reading, intermediary files, or any number of 'workarounds', but your RAM is still a soft cap on memory allocation.

Unimportant 18 Junior Poster

Poster above you was correct, please look at how this is different from what you did.

class myplayclass
    {
    public:
    int x;
    int y;
    vector<int> myVofInt2;
    myplayclass() : myVofInt2(10) {} // you can call its constructor like this
    ~myplayclass(){}
    myplayclass(int intX):x(intX), myVofInt2(10) {y=0;}
    };
     
    int _tmain(int argc, _TCHAR* argv[])
    {
    vector<int> myVofInt(10);
     
    return 0;
    }
Jsplinter commented: Thank you very much, I didn't realize there was a difference +1
Unimportant 18 Junior Poster

cout << line[count] // <--- you are returning uninitialized data, as the variable count can be greater than the size of your input.

Unimportant 18 Junior Poster

Is the file in the same directory as the .h you are editing?

Unimportant 18 Junior Poster
switch( var ) {
  case 1:
    // ;
    break;
  default:
    std::cout << "Default." << std::endl;
    break;
}

Any case except the integer 1 will output "Default.", as it is the default statement.

I cannot think of a different context for this question, if it's something else you'll need to be more specific.

Unimportant 18 Junior Poster

Is dt ever negative?
That could give you an undefined value depending on what complex math classes you are using.

In the real number system, a negative number has no square root (imaginary numbers required), as any number multiplied by itself will be positive.

As a quick test, why don't you try this:
sqrt(abs(dt))

and see if the NaN outputs are removed, if so, as this would lead to incorrect answers, you will likely have to create or use a class which can support complex number mathematics (such as imaginary numbers).

Best of luck!