daviddoria 334 Posting Virtuoso Featured Poster

You could use std::vector's of std::vector's - then you don't have to worry about new() and delete().

daviddoria 334 Posting Virtuoso Featured Poster

the compare() function is just like "==" for std::strings.

daviddoria 334 Posting Virtuoso Featured Poster

Surely the source code is not 18MB, try deleting the files that Ancient Dragon mentioned.

daviddoria 334 Posting Virtuoso Featured Poster
#include <iostream>

is where you will find cout, etc.

namespaces are ways to group functions - for example, the cout, etc you are looking for are in the std namespace, so you have to call them like this:

#include <iostream>

int main()
{
std::cout << "something" << std::endl;
return 0;
}

Other useful things in the std namespace:

#include <vector>
#include <string>
etc.

good luck

dave

daviddoria 334 Posting Virtuoso Featured Poster

I believe the preferred method of reading all the lines in a file is this:

std::string line;
	
while(getline(fin, line))
{
	//the current line is now in "line", handle it
}
daviddoria 334 Posting Virtuoso Featured Poster

I believe what ithlep means for you to do is

MyFrame *mainFrame = new MyFrame(wxT("Test Harness"), wxSize(700, 600) ); 
if(mainFrame)
  mainFrame->Show(true);
else
  std::cout << "There was an error creating mainFrame!" << std::endl;
daviddoria 334 Posting Virtuoso Featured Poster

Please provide the smallest possible segment of code that isn't working, along with example input and actual output vs expected output.

daviddoria 334 Posting Virtuoso Featured Poster

Where is CString declared? Is it a visual studio thing? Because CString is definitely not a standard c++ thing.

daviddoria 334 Posting Virtuoso Featured Poster

You could also use an std::vector of your struct to avoid almost every problem that will come up.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

The first compiler error I get is that your struct data_to_pass_st isn't defined anywhere. Also, I don't know where common.h is - maybe it is a windows thing?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Sounds like he was asking more about GUI type stuff rather than 3d graphics? In linux, there are a couple of main GUI libraries like QT and GTK. I'm not sure about windows. They usually have some kind of graphical designer that you can layout buttons and textboxes and whatnot, then they use some variation on the idea of "callbacks" - an event gets triggered when the user does something in the GUI and then you have to "handle" the event in the code.

Sorry, I don't know anything about windows GUIs in c++.

Good luck.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

You don't have a semicolon after num++. There is no reason that I should have to compile your code to find out what the compiler errors are... post the compilers output next time. Also, there is not need to post 10 line cout statements, you should post the simplest working example possible. The following code has the same problems, but is much shorter.

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

using namespace std;
int main ()
{
	int num;
	do
	{
		cout<< "something" <<endl;
		cin>>num;
		cout<<endl;
		num++
	
	}while(num!=0);

	switch (num)
	{

		case (0):
			cout << "End of program"<<endl;
		case (1):
			cout<<"something else"<<endl; 
			break;
		default:
			cout<<"Invalid number. Please choose again.";
			break;	
	}
	return 0;
}

You don't seem to be handling case 0 at all, if you want to end the program you could use

return 0;

or

exit(-1); //from stdlib

Dave

daviddoria 334 Posting Virtuoso Featured Poster

what is the problem?

daviddoria 334 Posting Virtuoso Featured Poster

Here is a good explanation of left shift (<<) and right shift (>>)
http://irc.essex.ac.uk/www.iota-six.co.uk/c/e5_bitwise_shift_operators.asp

Dave

daviddoria 334 Posting Virtuoso Featured Poster
newcook88 commented: Thank you for the link i wud appreciate if u can show a method to print the output that vector +1
daviddoria 334 Posting Virtuoso Featured Poster

What platform are you on (linux or windows)?

daviddoria 334 Posting Virtuoso Featured Poster

Is this an open source thing that we can download and try to compile? If so, please post a link.

Dave

daviddoria 334 Posting Virtuoso Featured Poster
daviddoria 334 Posting Virtuoso Featured Poster

Ok so Puzzle is a public member variable of Sudoku. To access it in main, you have to first create an instance of your Sudoku class

Sudoku MySudoku;

Then you can access the Puzzle variable like this

MySudoku.Puzzle[x][y];

You mentioned that Puzzle was filled, but that code must be in your Sudoku.cpp file. Also, why call the file doth.h when it is a Sudoku class?

daviddoria 334 Posting Virtuoso Featured Poster

Is puzzle a member of a class? Or just a global variable that was created in the .h file? Can you post your .h file?

daviddoria 334 Posting Virtuoso Featured Poster

You say

if (Puzzle[ptx]...

but you haven't defined Puzzle anywhere!

daviddoria 334 Posting Virtuoso Featured Poster

I really never use arrays, I go for the vector of vectors

vector<vector<char> > array(columns);
for(unsigned int i = 0; i < columns; i++)
{
vector<char> RowVector(rows);
// ... fill the row vector ...
   array.push_back(RowVector);
}

If you want to use an actually array you have to use "new", because as it's telling you, you aren't allowed to determine the size of an array declared like you were doing it at runtime.

daviddoria 334 Posting Virtuoso Featured Poster

I do it just to remind myself (and the compiler) that no class variables can be changed in this function. Basically just to keep me from accidentally doing something stupid!

ie.

double YourClass::GetX()
{
  x_ = 2.0;
}

You should not be modifying any of the member variables in a get function! But the compiler doesn't know that, unless you do this:

double YourClass::GetX() const
{
  x_ = 2.0;
}

Then it will give you an error, because you are not allowed to modify x_ from this function!

Hope that helps,

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Which line do you get the pointer comparison error?

In this code:

int random_integer = (rand()%6)+1;
random_integer = pcdice1;

You are storing the random number in random_integer, and then immediately replacing it with pcdice1. That is why you aren't seeing a different number each time.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I don't understand the relationship between truck_data and position_axle

Maybe give a sample input/output?

daviddoria 334 Posting Virtuoso Featured Poster

You seem to have not tried at all. Give it a shot and then if it doesn't work we'll help you.

Salem commented: Quite so +29
daviddoria 334 Posting Virtuoso Featured Poster

But look how easy this is!

ifstream fin(Filename.c_str());

	if(fin == NULL)
		cout << "Cannot open file." << endl;

	vector<string> Lines;
	string line;
	
	while(getline(fin, line))
	{
		Lines.push_back(line);
	}
	
cout << "NumLines: " << Lines.size() << endl;

	for(unsigned int i = 0; i < Lines.size(); i++)
		cout << Lines[i] << endl;
daviddoria 334 Posting Virtuoso Featured Poster

Why not use a vector<string>? Then you can use getline() :)

daviddoria 334 Posting Virtuoso Featured Poster

Yep, the const is just so you stop yourself from accidentally changing it if you don't want to change it. The reference is so it does not get copied by value which, as you say, is to save memory and I guess time. Even though you can't change it, the reference means you are looking at the values from the original variable.

daviddoria 334 Posting Virtuoso Featured Poster

I always pass things as const if the function will not change them. Also you should pass anything bigger than a single int or double by reference. Both techniques are shown here:

int compare(const string &target, const string &s)//outputs # of correct characters
{
	int alike = 0;
		for (int i = 0; (unsigned int)i < target.length(); i++)
		{
			if (target[i] == s[i]) alike++;
		}
	return alike;
}

Goodluck!

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Don't simply post your code - ask a question!

daviddoria 334 Posting Virtuoso Featured Poster

nope, if you make an array of length 5

int test[5];

then you have to use elements 0 to 4

for (i=0; i<5; i++)
daviddoria 334 Posting Virtuoso Featured Poster

Note that c++ arrays are 0 based. That is, array[0] is the first element, not array[1].

Dave

daviddoria 334 Posting Virtuoso Featured Poster

please use code tags

daviddoria 334 Posting Virtuoso Featured Poster

There are also linux utilties dos2unix and unix2dos (or something like that) that will convert the line endings to the appropriate type.

I'm glad you got it working.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Probably more of a linux question than a c++ question.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I don't see "store" defined anywhere?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

The constructor of your class simply needs to be called after the values have been input, and passed those input values.

class Person
{
string Name;
int Age;
Person(const string name, const int age) : Name(name), Age(age) {}
};

That syntax is called an "initialization list". It means class variables are assigned during the construction of the class.

int main()
{
//input from user
string name;
int age;
cin >> name >> age; //or however you want to input them
Person(name, age);
}

That should construct the class with the user input values.

Hope that helps.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

cout<<input * (input-1)<<"\n"; //multiplies it all together

that line is not dependent on the function call before it.

also, you should call your function "factorial" instead of "recurse". The recursiveness should be implied by the behavior, it shouldn't need to be stated explicitly.

Dave

daviddoria 334 Posting Virtuoso Featured Poster

I dont' really understand either, but maybe you just want to put a vector in the derived class instead of in the base class?

daviddoria 334 Posting Virtuoso Featured Poster

1) make sure you open the file in append mode in the add() function (i'm not sure what the default mode is)

2)there is no need to do

while (!a.eof()){
getline(cin, line);

you can simply do

while(getline(cin,line))

If you don't tell us what's wrong, we can tell you how to fix it! (unless we compile it ourselves - which you're supposed to do for us! haha)

Dave

daviddoria 334 Posting Virtuoso Featured Poster

didn't we answer the question??

daviddoria 334 Posting Virtuoso Featured Poster

yea, vector's have a size() function

vector<int> A(5); //declare a vector of length 5
cout << A.size() << endl;
daviddoria 334 Posting Virtuoso Featured Poster

what do you mean xeuron?

daviddoria 334 Posting Virtuoso Featured Poster

you could use a vector instead of an array

#include <vector>

then you can return a vector<int> and not have to worry about every saying pointer!

Dave

Salem commented: Definitely the best idea +25
daviddoria 334 Posting Virtuoso Featured Poster

yep, exactly the same thing in this case because we haven't used any of the "fancy" ideas of classes. Just replace "class" with "struct".

Dave

daviddoria 334 Posting Virtuoso Featured Poster

Hmm I think you're mistaken

You should do something like this

class TaxInfo
{

float totfedtax;
float totssitax;
float totstatetax
etc...
};

void Averager(TaxInfo &MyTax)
{
do stuff to MyTax.totfedtax, etc
}

see how clean it is!?

Dave

daviddoria 334 Posting Virtuoso Featured Poster

whoa.. that's just asking for trouble. You should make a struct or a class to contain all that information and just pass around 1 variable, not 20!

Dave