twomers 408 Posting Virtuoso

No. It's just a text file... say you have a text file called settings.txt which has the details you want in it. Read in the values from that and use them in your program. I do it via something like:

bool readSettings( std::map<std::string,std::string> &settings, const std::string &fname ) {
  std::ifstream in( fname.cstr() );
  if ( !in )
    return false;

  std::string line;
  size_t colonPosition;
  while ( std::getline( in, line ) ) {
    colonPosition = line.find( ":" );
    if ( colonPosition != std::string::npos ) // not found
      settings[line.substr( 0, colonPosition)] = line.substr(colonPosition+1); 
  }

  return true;
}

(note, hasn't been tested. Might have to modify)
And the settings file would be like:

NAME:twomers
AGE:22

Then I'd call it like:

#include <fstream>
#include <string>
#include <map>
#include <iostream>

bool readSettings( std::map<std::string,std::string> &settings, const std::string &fname ) {
  std::ifstream in( fname.cstr() );
  if ( !in )
    return false;

  std::string line;
  size_t colonPosition;
  while ( std::getline( in, line ) ) {
    colonPosition = line.find( ":" );
    if ( colonPosition != std::string::npos ) // not found
      settings[line.substr( 0, colonPosition)] = line.substr(colonPosition+1); 
  }

  return true;
}

int main() {
  std::map<std::string,std::string> settings;
  readSettings( settings, "settings.txt" );
  std::cout<< settings["NAME"] << " is " << settings["AGE"] << " years old\n";

  return 0;
}

Note though that this doesn't validate the existence of these elements in the map. If you don't know a map is something which correlates one variable to another, here one string to another. The first describes the second in a unique way.

twomers 408 Posting Virtuoso

Saving settings simply involves saving details to a file. Normally there are a number of variables you require, say name, age, etc. So I save them in a file like so:

USERNAME:twomers
USERAGE:22

Then I read in the file into a std::map<std::string,std::string>. The first parameter is the bit of the line before the : and the second is the bit afterwards. So I'd use it like:

std::cout<< "Hello, " << settings["USERNAME"] << ".";

Edit: I read it in like:

settings[line.substr( 0, colonPosition)] = line.substr(colonPosition+1);

where line is the result of reading the settings file via:

std::getline( inStream, line );

include string and fstream.

twomers 408 Posting Virtuoso

I think williamhemsworth's right, but I think you can export all members of a class in one swoop:

dll.h

#include <iostream>

#ifdef TWOMERS_BUILD_DLL
  #define TWOMERS_EXPORT __declspec(dllexport)
#else
  #define TWOMERS_EXPORT __declspec(dllimport)
#endif

class TWOMERS_EXPORT myClass {
  private:
    int thing;

  public:
    int returnThing();
    void setThing(int _thing);
};

dll.cpp:

#include "dll.h"

#define TWOMERS_BUILD_DLL

int myClass::returnThing() {
  return thing;
}
void myClass::setThing(int _thing) {
  thing = _thing;
}

Might be worth wrapping functions in a class if you want to save yourself some typing. Otherwise bite the bullet.

twomers 408 Posting Virtuoso

It depends on my mood. I like it with nothing, sugar, milk, or cream and most combinations of the above, haven't tried it with milk and cream, but all others stand depending on my mood. I had it with a little milk today. But, like JBennet, I prefer tea. In particular Barry's Tea. Mmm.

twomers 408 Posting Virtuoso

You can do this quite elegantly with the STL... might be advanced, I dunno.

#include <fstream>
#include <vector>
#include <string>
#include <algorithm>

bool char_sort_function( char a, char b ) {
  return a>b;
}

int main( int argc, char *argv[] ) {

  // File contains: This is a test!
  std::ifstream in( "test.txt", std::ios::binary );

  if ( in ) {
    std::vector<char> vchar;

    // Read characters into vector 
    vchar.insert( vchar.end(), std::istream_iterator<char>(in), std::istream_iterator<char>() ); 

    // Sort them
    std::sort( vchar.begin(), vchar.end(), char_sort_function );

    // Prints characters
    std::copy( vchar.begin(), vchar.end(), std::ostream_iterator<char>(std::cout, "\n") );
  }

  return 0;
}

Edit: Note, this ignores whitespace.
Also change

#include <iostream.h>
#include <fstream.h>
#include <string.h>

to

#include <iostream>
#include <fstream>
#include <string>
twomers 408 Posting Virtuoso

libcurl. It's fairly straightforward after you get used to it.

Edit: Once you get the library working this should pretty much do the trick. Just open the file in binary mode and I think it should work.

twomers 408 Posting Virtuoso

In Ireland it's about €1.10 a litre, a gallon is 3.785411784 litres, which translates to about $5.20 for a gallon of Irish petrol.

How do ye decipher between petrol and diesel? Are they both called gas?

twomers 408 Posting Virtuoso

Well, if you put an using namespace std; in the code somewhere you don't need the std in front of things.

twomers 408 Posting Virtuoso

I know, but I'm not going to give you the complete answer. Modify the code I gave there to work with your stuff. The std::copy function just prints the array to the console. The thing is that you need to define, yourself, the functions which can determine whether one element of the array can be considered bigger/smaller than another.

twomers 408 Posting Virtuoso

Manipulate this to your needs:

#include <algorithm>
#include <iostream>

struct thing {
  int a, b;
};

std::ostream& operator << (std::ostream &o, const thing &th ) {
  o << "a: " << th.a << ", b: " << th.b;
  return o;
}


// Comparison functions
bool comp_thing_a (thing i,thing j) { 
  return (i.a<j.a); 
}
bool comp_thing_b (thing i,thing j) { 
  return (i.b<j.b); 
}


int main( int argc, char *argv[] ) {
  thing i_thing[10];
  int myints[] = {32,71,12,45,26,80,53,33, 26, 11};
  for( int i=0; i<10; i++ ) {
    i_thing[i].a = myints[i];
    i_thing[i].b = myints[9-i];
  }
 
  // Arrange according to i_thing[x].a
  std::sort( i_thing, i_thing+10, comp_thing_a );
  std::copy( 
    i_thing, 
    i_thing+10, 
    std::ostream_iterator<thing>(std::cout, "\n") );
  
  std::cout<< "\n\n";

  // Arrange according to i_thing[x].b
  std::sort( i_thing, i_thing+10, comp_thing_b );
  std::copy( 
    i_thing, 
    i_thing+10, 
    std::ostream_iterator<thing>(std::cout, "\n") );


  return 0;
}
twomers 408 Posting Virtuoso

Two things first. Use <iostream> and not <iostream.h>. Also use int main() and not void main().

What problem did you encounter? It might be best to encapsulate the variables in a structure, and then make an array of 80 of these structures so that the name, gender and CGPA of one student remains with that student, ie so you don't have to rearrange the genders and CGPAs in relation to the name. std::sort might be of use.

twomers 408 Posting Virtuoso

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 way is to provide the equivalent hypotenuse of the a and b points (i.e. sqrt(a^2 + b^2)), and the angle between the origin (be it natural origin or a secondary), and the point a+ib (i.e. atan(b/a)). Might seem overly complicated, but it's good for multiplying and dividing imaginary numbers, though rectangular is better for addition and subtraction.

ohnomis commented: Knows complicated math for complex numbers lol. =) +1
twomers 408 Posting Virtuoso

This year my family is doing a secret santa, so instead of having to conceive of seven presents to buy one! I bet I'll still (A) buy a bad present, (B) leave it late and (C) buy it for the wrong person though.

twomers 408 Posting Virtuoso

There's a joke going around Ireland that goes along these lines... "A police man stops a car that's filled with five guys wearing white robes with hoods. It's late at night and he asks the driver where he's going, to which he responds 'We're going to Killbarrack'." Made me chuckle anyway.

Dave Sinkula commented: Hehe and welcome to the terror watch list. :icon_razz: +17
twomers 408 Posting Virtuoso

I don't know about a name for the shop, but your caption could be: "Hang the wife. Shoot the family. Frame the kids." I saw it on a shop somewhere else and it stuck.

Shanti C commented: nice quotation .... +2
Aia commented: :) +10
twomers 408 Posting Virtuoso

I wasn't going to, but then I got bored so I did. These are the ones Grim got bored of answering.

...

>> Why is it that people say they "slept like a baby" when babies wake up like every two hours?
Babies can sleep anywhere; in cars, on people, during weddings, with no problem

>> If a deaf person has to go to court, is it still called a hearing?
Of course it is. What kind of stupid conjecture is that? It's a hearing of the state's case against a party.

>> Why are you IN a movie, but you're ON TV?
Movies aren't physical. Televisions are. As to why that would lead to a difference in grammar... I don't know, but that's the only difference I could see.

>> Why do people pay to go up tall buildings and then put money in binoculars to look at things on the ground?
Cause people have too much money. Also it's more efficient - you can see far more from a higher distance so you don't have to move as far.

>> Why do doctors leave the room while you change? They're going to see you naked anyway.
Just cause they see you in the nip they don't have to see you bend over during the process.

>> Why is "bra" singular and "panties" plural?
English is a weird language.

>> Why do toasters always have …

twomers 408 Posting Virtuoso

That claims ye're the last remaining superpower... pff.
What are national ID cards (past the obvious)? I landed between the 'n' and 't' of the centre... should be noted I didn't read most of the questions and didn't understand the rest.

twomers 408 Posting Virtuoso

printf()....

Oh and include stdio.h instead of iostream. And time.h instead of ctime.

Also, C doesn't have references, so you'll have to convert those reference parameters to pointers.
Just out of curiosity, why do you want to convert it to C?

See here.

twomers 408 Posting Virtuoso

>> Good job i did physics once.
You'll save the world you will, Serunson. I feel save in your hands.
Edit: Or rather with your mind!

twomers 408 Posting Virtuoso
twomers 408 Posting Virtuoso

What a great country.

twomers 408 Posting Virtuoso

In fact I think this question is completely off the wall. Toy guns can't hurt anyone so why bother asking if kids should play with them or not. What you should be asking is if kids should play with guns. I, for one, don't think they should.

twomers 408 Posting Virtuoso

http://gizmodo.com/5062385/computer-nearly-passes-turing-test-for-artificial-intelligence

I dunno though... real AI should learn. So after a number of conversations it should get better.

twomers 408 Posting Virtuoso
twomers 408 Posting Virtuoso

I figure the problem might be in declaring a local variable called rowNum while at the same time having a parameter called the same. Also, your function doesn't return anything. For future reference please post the errors/warnings you get too.

twomers 408 Posting Virtuoso

Jean Michelle Jarre is a fraud. http://www.youtube.com/watch?v=G3SMB-YQ56s (two minutes in, complements to Aia)

twomers 408 Posting Virtuoso

>> and I never really shot anyone with a real gun
That vague denial of shooting nobody doesn't fill me with confidence.

>> Take the kids to a range. Let 'em shoot.
I probably don't believe this, but it's funny

THE BEST COMEBACK LINE for 2007… For those that don’t know him, Major General Peter Cosgrove is an “Australian treasure!”General Cosgrove was interviewed on the radio recently. You’ll love his reply to the lady who interviewed him concerning guns and children. It is a portion of an ABC interview between a female broadcaster and General Cosgrove who was about to sponsor a Boy Scout Troop visiting his military headquarters.
FEMALE INTERVIEWER:
So, General Cosgrove, what things are you going to teach these young boys when they visit your base?

GENERAL COSGROVE:
We’re going to teach them climbing, canoeing, archery and shooting.

FEMALE INTERVIEWER:
Shooting! That’s a bit irresponsible, isn’t it?

GENERAL COSGROVE:
I don’t see why, they’ll be properly supervised on the rifle range.

FEMALE INTERVIEWER:
Don’t you admit that this is a terribly dangerous activity to be teaching children?

GENERAL COSGROVE:
I don’t see how. We will be teaching them proper rifle discipline before they even touch a firearm.

FEMALE INTERVIEWER:
But you’re equipping them to become violent killers.

GENERAL COSGROVE:
Well, Ma’am, you’re equipped to be a prostitute, but you’re not one, are you?

The radio went silent and the interview ended

Aia commented: Hehe +10
Dave Sinkula commented: I always liked that story. +17
twomers 408 Posting Virtuoso

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.

twomers 408 Posting Virtuoso

Surely the computer's gonna talk l33t so it can't be distinguished from any other 13 year old girl on the net. Of course it's gonna succeed.

scru commented: Ha +3
twomers 408 Posting Virtuoso

Does ifstream::get read whitespace? I think it can. Use .get() instead of using the >> operator. i.e. plainVector.push_back( cyphFile.get() );

twomers 408 Posting Virtuoso

To copy a file you basically need to first read that file. To do this read about opening ifstreams as binary files ( http://www.cplusplus.com/reference/iostream/istream/read.html ), might want to edit that code a bit. Then you'll want to save the contents of what you read to an output file, ofstream is your weapon of choice here ( http://www.cplusplus.com/reference/iostream/ostream/write.html )... In fact the latter link has basically your program... Write some user-input/command line parameter processing around it to allow a user to select the input and output files and hey presto done.

twomers 408 Posting Virtuoso

Why don't you just do myArray[counterArray] = new unsigned long; in the allocation loop? And don't forget to delete everything too! Considering what you basically want is a 50-element array why don't you do unsigned long *array_50 = new unsigned long[50]; , and then access via the [] operator as per above code. Then you'll only need one delete call: delete []array_50; .

At a guess I'd imagine if you changed the function to: unsigned long printArray(unsigned long *anArray[]) , and call it as follows printArray(myArray); , it should work.

twomers 408 Posting Virtuoso

Sorry, dude. Looks like you were out too even though you started this thread.

twomers 408 Posting Virtuoso

Hey, lardy, you forgot me! Grr.

twomers 408 Posting Virtuoso

Least you're honest...

Good luck with that assignment.

twomers 408 Posting Virtuoso

Why not? I made it to 2k in another forum and didn't notice until I was at 2050 ish.

twomers 408 Posting Virtuoso

What do you mean by three tear?

All VC programs must be projects... So open up the program. Go to "File -> New -> Project -> Visual C++ Projects -> Win32 -> Win32 Console Project", or similar. I'm on MSVC '03 so the menu's probably slightly different in whatever one you're using. Then press Ctrl+F5 to build and run (again in '03)

twomers 408 Posting Virtuoso

Just had an omelet with toast and am currently drinking tea.

twomers 408 Posting Virtuoso

>> Gee, what more do you want?
A clickable link would be nice. I don't want to have to copy and paste again, Salem!

twomers 408 Posting Virtuoso

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 fstream. I never liked using fstream much. But am normally not in a situation where I need to read and write at the same time either.

twomers 408 Posting Virtuoso

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 not?

twomers 408 Posting Virtuoso

I think the LHC is wonderful.

twomers 408 Posting Virtuoso

I think what you're looking for is erase.

twomers 408 Posting Virtuoso

It's do-while.

do {
 // code here
} while( condition );
twomers 408 Posting Virtuoso

A loop's a loop. It doesn't matter how you do it. It's entirely equivalent. No matter which you choose all should produce the same five-time iteration that you want. I'd use for but a while would work too.

twomers 408 Posting Virtuoso

As far as I remember multiplication in the frequency domain is more efficient than convolution in the time domain, so fft the signals and multiply 'em out. Also, if you're doing a PhD in physics I'd assume that you'd have access to mathematically orientated software. This is much more easily accomplished via something like Matlab.

twomers 408 Posting Virtuoso

>> He is right about HO's mother -- she was white trash. But we can't blame HO for the sins of his parents.
Who's HO?

twomers 408 Posting Virtuoso

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 respective 'next' elements in the list. So iter->next (in the first iteration of the for loop), is entirely equivalent to l->next , which is the only list I'm using. And in the second iterator of the for loop iter->next is the same as l->next->next . Get me? iter is a pointer whose only purpose is to iterate through all the elements of the linked list.

twomers 408 Posting Virtuoso

I'd imagine you should change:

total = (kilowatt - 15) * 20 + 10 + compute_tax(total);

to

total = (kilowatt - 15) * 20 + 10;
total += compute_tax(total);

, but again check your formulae are correct.

twomers 408 Posting Virtuoso

For dynamic arrays first forget anything about uppercasing for the moment and read about the new and delete keywords. This is how C++ dynamically allocates memory. So after you're familiar with this read an (unsigned) integer via cin . Use new to allocate the array of the size the integer specifies. cin.get() that array. Then use toupper() . Then delete[] the array.