daviddoria 334 Posting Virtuoso Featured Poster

Yes, I understood the problem - did you look up delimiters and string parsing?

daviddoria 334 Posting Virtuoso Featured Poster

What have you tried? Lookup "delimiters". Also, unless I'm mistaken, Turbo c++ and Dev c++ are simple IDEs, not languages, right?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I think you'd have a lot better luck on the OpenCV forum.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Since this is a non-native c++ thing, I would recommend using system() to call the appropriate system command to get the terminal size (I don't know what it is, but I'm sure one exists). Include in the command writing this result to a file. Then read the file in your c++ program.

In bash it is:

system("echo $COLUMNS $LINES > file.txt");

Hope this helps.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

May I suggest a new thread titled "How do you catch F5 key?"

daviddoria 334 Posting Virtuoso Featured Poster

Look into fstream/ofstream

Dave

daviddoria 334 Posting Virtuoso Featured Poster

'outfile' doesn't seem to be defined.

This code works fine for me:

#include <iostream>

using namespace std;

int main()
{
    string text;
    int nl = 0;

    cout<<"Press enter twice in a row to quit: ";

    while (nl < 2 && getline(cin, text))
    {
        if (text.empty())
        {
            ++nl;
        }
        cout << text << endl;
    }
       
    return 0;
}

Dave

daviddoria 334 Posting Virtuoso Featured Poster

So you want me.txt to open in notepad and you.exe to execute?

daviddoria 334 Posting Virtuoso Featured Poster

replace x>sizl with x<sizl

daviddoria 334 Posting Virtuoso Featured Poster

This compiles and runs fine for me:

#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;

class Hardware
{
  int a;
};

int main()
{

	Hardware tool1;
	ofstream st("Hardware.dat", ios::out | ios::binary);
	if(!st)
	{
		cout << "File not found.";
		exit(-1);
	}
	for(int i=0; i<100; i++){
		st.write(reinterpret_cast<const char*>(&tool1),sizeof(Hardware));
		}
	cout << "\nCreated 100 blank tools.";
    
    return 0;
}

If you can make something approximately this length that produces the out of range error that would be very helpful.

daviddoria 334 Posting Virtuoso Featured Poster

That would just write the same tool 100 times, right?

Please clearly define what is going on - what is your expected output? What is the current output? Are there compiler errors?

daviddoria 334 Posting Virtuoso Featured Poster

You're right, of course how you're exiting doesn't matter to your real problem. I was just pointing it out in parallel.

Another thing - I would highly recommend explicitly using the "this" pointer to indicate when you are addressing member variables:

void Hardware::setToolName(string tn)
{
	for(int i=0; i < 15; i++)
		this->toolName[i]=tn[i];
}

It will really improve code readability.

This is the demo I have for writing a binary file:

float fnum[4] = {11.22, -33.44, 55.66, 77.88};
	int i;

	ofstream out(Filename.c_str(), ios::out | ios::binary);
	if(!out)
	{
		cout << "Cannot open file.";
		exit (-1);
	}
	
	out.write((char *) &fnum, sizeof(fnum));
	out.close();

Maybe this will help you get a bit further?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I don't know if everyone here agrees, but I am much more inclined to help when the code is immediately compilable:

#include <iostream>
#include <fstream>
#include <cstdlib>

using namespace std;

class Hardware
{
  int a;
};

int main()
{
    Hardware tool1;
	ofstream st("Hardware.dat", ios::in | ios::out | ios::binary );

	if(!st)
	{
		cout << "File not found.";
		exit(0);
	}

	int myRecordNumber;
	char tname[15];
	int myQuantity;
	double myCost;

	cout << "Enter tool number: " << endl;
	cin >> myRecordNumber;

	cout << "Enter tool name: " << endl;
	cin >> tname;

	cout << "Enter the quantity: " << endl;
	cin >> myQuantity;

	cout << "Enter the cost: " << endl;
	cin >> myCost;

	st.seekp((myRecordNumber)*sizeof(Hardware));

    st.write(reinterpret_cast<const char*>(&tool1),sizeof(Hardware));
    
    return 0;
}

First - I think you should typical exit(-1) to indicate an error, right? I think exit(0) ( like return 0) means "everything went ok" (but maybe I'm wrong about this?)

When I run this code, I get "File not found". Since you are using ofstream, this should be trying to write (create) the file, right? So it shouldn't matter if the file is already created?

daviddoria 334 Posting Virtuoso Featured Poster

Yes yes, too long! haha - Try to abstract the problem to < 20 lines that we can look at.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Please use code tags to post the smallest compilable example of the problem. Subscript out of range means you are doing something like myArray[5] when the array only has 3 elements, or something like that.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Please use code tags to post the relevant parts of the code - no one wants to look through 10 files!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Sounds like you need to make a "Fraction" class and then make an array (I'd recommend a std::vector) of Fraction objects.

std::vector<Fraction> fractions;

I hope this gets you started - once you get some code written post it here and I'm sure someone can help you with any difficulties.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You're going to have to show some effort before anyone is going to help you with your project. Have you written any code so far? I'm not sure how they're expecting you to know the form/shape of the letters - do you have any additional input files? (b/w images of letters, etc)?

Dave

Laurentius Dion commented: not bad +0
daviddoria 334 Posting Virtuoso Featured Poster

Ah, didn't see that app|ios::binary.

daviddoria 334 Posting Virtuoso Featured Poster

This does not look like standard/modern c++. You should #include <iostream> instead of #include<iostream.h> Then you should do the reading with the >> ifstream operator instead of .read and the << ofstream operator instead of .write.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I didn't look closely, but my first thought is to try std::vector<std::string> - is there a reason you need it to be std::vector<char*> ?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

First, you need to put a space between the two angle brackets:

vector<pair<double,double> > *point; //points = x,y respectivly

instead of

vector<pair<double,double>> *point; //points = x,y respectivly

It should not only compile (which it doesn't):

(.text+0x18): undefined reference to `main'

but also have a simple use case - an example where we can compile, run, and see the error.

FotG2 commented: Formating of a program is the programmers choice and when is related to a single space should not be remarked on +0
daviddoria 334 Posting Virtuoso Featured Poster

Can you post a compilable example of your problem?

daviddoria 334 Posting Virtuoso Featured Poster

Can you post a compilable example of your problem?

daviddoria 334 Posting Virtuoso Featured Poster

Is this what you're looking for?

#include <iostream>
#include <map>


int main(int argc, char *argv[])
{
	
	std::multimap <int, double> MyMap;
	
	//create a mapping from "testone" to 111
	MyMap.insert(std::pair<int, double>(1, 1.2));
	
	//create an iterator
	std::map<int, double>::iterator iter;

	iter = MyMap.find(1);
	
    if(iter == MyMap.end())
    {
      std::cout << "Not found." << std::endl;
    }
    else
    {
	std::cout << "Found: " << iter->second << std::endl;	
    }
    
	return 0;
}

Dave

sciwizeh commented: Just the info I needed +2
daviddoria 334 Posting Virtuoso Featured Poster

If the error happens at runtime (as you say "when the balanced() function calls stack.push"), then it is not a linker error. But the errors you posted ARE linker errors. I don't use visual studio, so unfortunately I can't tell you how to tell it that you want to link to all of the object files generated by all of your source files. Maybe someone else can.

Good luck.
Dave

daviddoria 334 Posting Virtuoso Featured Poster

What command are you using to compile/link? What are the names of those files posted above? Is this the absolutely smallest code that will demonstrate your problem?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I really recommend you try to narrow the problem down to a ~ 15 line demonstration of the problem that we can look at. You should use a debugger to step through the code until you reach the line that it is crashing on - code after that is certainly irrelevant. And I'd bet much of the code before that could be removed without disrupting the problem.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I'd recommending changing the title of your post. This isn't really that easy of a question (at least to me, haha). You should call it "Detecting splits in a btree"

Dave

Ancient Dragon commented: Agree. Not an easy question to me either. +28
daviddoria 334 Posting Virtuoso Featured Poster
int strSize = word_to_guess.size();
daviddoria 334 Posting Virtuoso Featured Poster

Here you have declared the variables, but then output just constant expressions...

I'd suggest googling for "basic c++" and trying some of the simple examples you find until you get familiar with the basics. Then you can try to write this triangle program as a demonstration to yourself that you've learned something!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

What you have there is simply a hard coded triangle. You need to write the code to setup the triangle's height and width. Give it a shot and post your problem once you try it.

daviddoria 334 Posting Virtuoso Featured Poster

1) The undefined reference is because you are not linking to SaveData.cpp. Which IDE are you using (Visual studio, etc)?

2) 'retreive' should be spelled 'retrieve'.

3) you seem to still be using the 5th element (element 4), when it is not valid.

4) it seems to work just fine when you change void outputSavedata (int* stats); to void outputSavedata (int stats[4]);

daviddoria 334 Posting Virtuoso Featured Poster

You have to create the array in the scope that you are going to use it! Probably the way to go here is have the retrieve() function accept a pointer to the array it will fill. Also, be careful not to use element 4 of an array[4] - it has 4 elements, 0,1,2,3!

#include <iostream>

void retreiveSavedata (int* stats);
void outputSavedata (int stats[4]);


int main()
{
	int stats[4];	
	retreiveSavedata(stats);
	outputSavedata(stats);
	return 0;
}

void outputSavedata (int stats[4])
{

	std::cout<< "\nStrengh:" << stats[0] << "\n";
	std::cout<< "Defense:" << stats[1] << "\n";
	std::cout<< "Hitpoints:" << stats[2] << "\n";
	std::cout<< "Experience:" << stats[3] << "\n";
	

}


void retreiveSavedata (int* stats)
{

	stats[0] = 0;
	stats[1] = 10;
	stats[2] = 20;
	stats[3] = 30;
	
}
daviddoria 334 Posting Virtuoso Featured Poster

Which IDE are you using? (Visual studio, KDevelop, etc) I know in KDevelop the little command window is broken such that it just ignores cin type statements... seems very odd but I always have to open a real terminal window and run the program if my program expects input.

daviddoria 334 Posting Virtuoso Featured Poster

This seems to work fine for me...

#include <iostream>
#include <fstream>

using namespace std;

void skrivtilfil (string placering);
void laesfrafil ();
int main()
{
	int ioro;
	cout << "in or out? ";
	cin >> ioro;
	if (ioro == 1)
	{
		std::cout << "Pressed 1. " << std::endl;
	}
	else if (ioro == 2)
	{
		std::cout << "Pressed 2. " << std::endl;
	}

	return 0;
}
daviddoria 334 Posting Virtuoso Featured Poster

I'm not sure what you're asking for help with, but you would want to overload << and >> so you could do something like this:

class A
{
int a,b;
};

int main()
{
A MyA;
cin >> A;
//instead of
/*
int a , b;
cin >> a >> b;
A.a = a;
A.b = b;
*/
return 0;
}

It's just much cleaner/easier to read, and it is a good to way to reuse code (so you don't have to do that little pattern over and over)

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I always advocate using an std::vector when possible.. can you do this:

std::vector<int*> yourVar(8);
daviddoria 334 Posting Virtuoso Featured Poster

VNL (part of VXL) has several multidimensional optimizers - http://vxl.sourceforge.net/

daviddoria 334 Posting Virtuoso Featured Poster

What do you mean "return only one of the values"? A function can only return one value, and it looks like yours is... maybe you can give an example input, expected output, and current output?

daviddoria 334 Posting Virtuoso Featured Poster

Please use code tags. You can find what you're looking for here:
http://www.learncpp.com/cpp-tutorial/93-overloading-the-io-operators/

daviddoria 334 Posting Virtuoso Featured Poster

I agree that it's generally a very bad idea - but if you DO have a good reason, compile with -Wno

daviddoria 334 Posting Virtuoso Featured Poster

I think you need to display the plot in a separate thread. This operation will vary from OS to OS.

daviddoria 334 Posting Virtuoso Featured Poster

I realize this is quite an odd/complicated problem, but can you reduce the amount of code necessary to produce it? Maybe you can play around and remove as many lines as possible and still produce the error. Often that will help you isolate the bug yourself, or if not, then it's much easier for us to dig in.

daviddoria 334 Posting Virtuoso Featured Poster

oh oh, what was I thinking hahaha, you can "return" the values by reference! What you'll need to do is put a '&' here:

void getSales(double &sales, double salesTotal)

and the same with bonus:

void calcBonus(const double RATE, double sales, double &bonus)
daviddoria 334 Posting Virtuoso Featured Poster

Well that's not gona work unless you make everything global, which is a TERRIBLE idea. displayBonus() wont work for the same reason unless you call it from calcBonus(). I duno what to tell you - the assignment is just wrong i guess :(

daviddoria 334 Posting Virtuoso Featured Poster

I don't understand, you are saying if it equals zero then "it is not a number"? Also, you can use this std::string Zero = "0"; then if(Zero.compare(buf)) actually, i think compare() returns the edit distance, so you need to see if it equals 0, so more like if(Zero.compare(buf) == 0)

daviddoria 334 Posting Virtuoso Featured Poster

The getSales() function shouldn't be void - it needs to return the sales!

daviddoria 334 Posting Virtuoso Featured Poster

Unfortunately I don't use windows so I can't try to help, but I have a hard time believing that error can't be produced in < 20 lines...

daviddoria 334 Posting Virtuoso Featured Poster

Please use code tags and post the smallest fully compilable example that demonstrates the problem.