tetron 22 Junior Poster

if you load the file #include <fstream> read in the file using std::ifstream("folder\\file.txt" now two options load into a single string or line by line.
Single std::string will be easiest

there are google articles on how to do this

The next thing is

std::string data;
//load data

//this is like an int showing current loc in string
std::string::size_type pos(0);
std::string::size_type cur_pos = data.find('<', pos);
if(cur_pos != std::string::npos)
{
//found the start of tag
//advance to first letter
+cur_pos
//now find end
 pos = data.find('>', cur_pos);
std::string tag = data.substr(cur_pos, pos - cur_pos); 
//check is closing tag
if(tag.size() > 0 && tag[0] = '/')
{
   tag = tag.substr(1);
   //are we inside or not
}
else
{
  //new tag
}

what else you have to do is add
a tag to an open std::vector<std::string> and if it closes it should be the last tag on the list
you have to store the strings between tags as parameters

now I have left a fair bit for you to do yourself here.

But if you assume no errors in xml and no self closing tags the
above methods should suffive

can anyone give me some hints on this im having issues

thanks

tetron 22 Junior Poster

First glance it is

using namespace std;

causes your compiler to find std::copy instead of copy
when it looks at copy

tetron 22 Junior Poster

Coming in late you have colours that you want to convert to different types and formats:

This would normally be a single set of formulae for each conversion and would not require a convert

but if you are pairing names with values and vice versa

couldn't you just use maps
one with key of string and colour value
one with key of the colour you want and string value.


otherwise a single pointer full look up could be implemented if speed is critical

edit: > hmm lots of posts came inbetween when I started and finished this

josolanes commented: Thanks for the ideas! :) +1
tetron 22 Junior Poster

Just a minor point:

php explode has a third optional parameter that limits the number of times to split

http://www.tizag.com/phpT/php-string-explode.php
so

std::vector<std::string> php_explode(const std::string &divide,
 const std::string &to_explode, int max_number = -1);

would be closer to the php_function signature but an easy modification to Nick's code

tetron 22 Junior Poster

Active window can have changed.

http://msdn.microsoft.com/en-us/library/ms633497(VS.85).aspx

is an EnumWindows function that appears to let you step through all of the windows
if GetDlgItem is failing to find your resource it could well be the wrong window although I though t it returned a handle

If this doesn't help the question might be down to how you are handling the messages do you then post a message to the window? Why can't maincontrol just be an event listener in a window?

how does your tab page (? type of tab control work)

Sorry, I'm probably being a bad understander today:)

tetron 22 Junior Poster

your code appears to moving around a bit and Iwould make sure that everything is as safe as can be

is pos an int?

ItemType *temp = new ItemType[pos];

them new would fail with a -1;
if so safer
to have

if (pos == 1)
	{
		a[0] = key;
		pos++;
	}
	else if(pos > 0)
	{

next where are a[] and pos coming from ?

is ItemType an typedef int as temp is being set to key an int so a warning should be showing or can its constructor throw

pos++;
int len = pos - 1;

little things like this means that you might want to check on paper for on case as
why not simply

int len(pos);
++pos; //what is this doing? it does nothing inside the function

finally does Heapify alter a or first it seems odd that you are going for 0 to first every time

there are many gaps in what you have shown which could cause a problem in your code you could perhaps use a vector and size() but for no rather than the debugger I would recommend placing in as much code safety as possible and if you use cout in between every function then you can find which line is throwing in case you have multiple errors it can be faster than stepping through the debugger each time.

but as you just have one a[] there are any number of …

tetron 22 Junior Poster

msdn is a good place to start :

http ://msdn.microsoft.com/en-us/library/system.windows.forms.systeminformation_properties.aspx

I think this is probably the one you wanted

your output from the functions could use std::string and then output with #include <iostream> & std::cout << or to a file

some of your coding seems unnecessarily non standard but this might in part be down to when you copied the code

tetron 22 Junior Poster

How are you currently linking to both libraries?

Project settings etc...

If I open one, only mine, header,

This last statement is a bit confusing are you saying you have source code for alglib, itk ?

tetron 22 Junior Poster

At a glance it looks as if the .dll is being included twice possibly under different names

as all the errors come from MSVCP90D.dll I am not sure how best to stop it though...

Thanks for reply!

Header files, which i include to my project, were provided with Alglib and ITK, so they are not self-made. I have only one header file with declaration of my one class.

I see it as well, that there could be some problem with namespace, any advice how to solve this?

tetron 22 Junior Poster

The use of active window might not be what you want.

Where are you creating the window?

If you have visual studio there are ways to avoid having to do all this.

But with an object like a button it is an object that has to be attached to a window so you first need to have a window to add it to.

The active window may not give you this level of control to be able to add things.

If you try going through the second example I gave to get a window to show with a button I think you might see the point that I am making.

the reason for ASSERTing that the handle was not 0 is in case you had not initialised the window propperly. It is tricky to create a window but once you have done it once the code does not alter.

I have had temporary good results using ff code:

CWnd* myWnd = GetActiveWindow();
CWnd* pControl = myWnd->GetDlgItem (IDC_EDT_XXX);
HWND hwndControl = pControl->m_hWnd;
pControl->SetWindowText("Good!!!");
pControl->InvalidateRect (NULL);
pControl->UpdateWindow ();

This worked once, after that the trigger event doesnt trigger any more and I get the Access Violation again.

tetron 22 Junior Poster

This will be my final post on this thread you'll be glad to hear.

my previous post probably shows a character flaw
but it had not been stated that it was an interview question in the original post and I assumed that this was a sample of how to populate an array from a book and this is what was the purpose of the original question.

while my explanation in both posts might have deserved a -1, I strongly felt that I had to clarify my reasoning. And I have been in interviews where a piece of C code is used for a discussion as C++ and the interviewers expected criticism of the code.

The variation of the code I found was the example:
http://www.cplusplus.com/reference/algorithm/generate/

where the function pointer at least makes the distinction between a constructor and operator() in the call to the UniqueNumber but it masks its behaviour with the g() in the example.

The operator() in essence is trying to emulate the behivour of std::vector constructor and overloading the return type means that the same written code can mean different things in different places.

It exists as a transition between struct and classes but has long since passed its necessity. Yes its behaviour is defined to the compiler but its logic is a work around when there is no need to use its implementation and it will not run faster.

As the OP stated in one of …

tetron 22 Junior Poster

I have become a little confused...

You want to add a button at runtime and then set its text?
At first glance what might be going wrong is the SetWindowText I think the button has to exist for this
to work and it doesn't until your create it.

to add a button as well as its constructor
you need to create it

try google or msdn:
http://msdn.microsoft.com/en-us/library/bw4e0cww.aspx

a tutorial that seems ok too is:

http://www.functionx.com/visualc/controls/button.htm

Your problem that you are showing there though is not dependent on the handle so I might not be answering your question very well.

tetron 22 Junior Poster
if(r1 > r2)
{
}

I had already given an example like this (see page 2) the purpose of the bool b was to try and demonstrate how the compiler interprets r1 > r2 and if(condition) but I might have missed the mark

tetron 22 Junior Poster

Ok lets get another -1

The point that I was making about the () is that its use makes the
code difficult to read, while not taking into account the operations that the computer has to perform.

It is half measure that does not make syntatic sense without knowing it is a special case

class foo
{
public:
 foo();
//operator() looks like a function called operator
 int operator() () {return 0;}
 std::string name;
}

how do you call this...

#include "foo.h"

int main()
{
foo * f = new foo();
int i = f->operator()();
foo f1;
int i = f1();
return 0;
}

Brackets should not follow operator precidence as they are a special symbol meaning do what is inside me first.
While when f1 is close to its declaration its purpose is clear if this is in real code

int i = f1();
//why not 
double d = f2();

there is no obvious connection between f1 and its class.
what is its real world meaning supposed to be.

There is no indication of purpose in the variable name!

While at first glance std::generate is a function that looks useful
the two example functions
of
1 - filling an array with incremental values
or
2 - rand(); are fundamentally different to use a function pointer and a specific function would seem clearest as what in effect is being done is casting the variable in example …

tetron 22 Junior Poster

This is going to be a stupid question, but If I do use the

//tet: changed the function name and removed friend
bool greater_than (Rational &Fraction1, Rational &Fraction2);

Operators are really just functions that the compiler can read in a user friendly manner

so to use this function

if(true == greater_than(r1, r2))
{
std::cout << "rational number r1 is bigger than r2" << std::end;
}

you should convert back to a single rational number I think if you work out in the short Rational example I gave whatshould go into the operator function it would help you

an operator> returns a bool this can be used with if etc

but it has a special layout

bool b = (r1 > r2);
if(b)
{
}
WaltP commented: Tetron, use periods and commas. I'll start infratcin if you keep making unreadable comments. -2
tetron 22 Junior Poster

I think first it is your save function

you have to first write n

int afisare()
{
    std::ofstream afisez;
    std::string fn("C:\\Documents and Settings\\test.txt");
    afisez.open(fn.c_str());
    if(afisez.is_open())
   {
//the missing feature
       afisez << n <<" ";
       for(int i=0; i<n; i++)
      {	
          afisez<<v[i]<<" ";
       }
       afisez.close();
   }
  else
  {
      std::cout << "could not open:" << fn <<  std::endl;
  }
return 0;
}

you should close() in citesr too
now my code works but you need a file to start the sort with
and that should be
sz vals

for example I used

10 0 3 6 9 2 5 8 1 4 7

and this gave

10 0 1 2 3 4 5 6 7 8 9

so the sort seems ok

:) Thanks for the exemple with vector..I find it very usefull
I also tried to replace my afisare function with the one you typed for me...but I have exactly the same results...

tetron 22 Junior Poster

Your problem maybe in using [] when you use int * the compiler does not know the size of v[]

I think int [] also works but you want to move onto std::vector and references int &i a reference lets you change the number without needing pointers

try

int afisare(int * v, int sz)
{
int ret(-1);
 ofstream afisez;
 afisez.open("test.txt");
 if(afisez.is_open())
 {
   ret = 1;//file open
   for(int i=0; i<sz; i++)
   {
     afisez<< *v <<" ";
     ++v;
   }
  afisez.close();
  }
}

an example of a function using a vector

void display(std::vector<int> &v1)
{
   int sz = v1.size();
  for(int i = 0; i < sz; ++i)
 {
   std::cout << v1[i] << " " ;
 }
 std::cout << std::endl;
}

also close your open in cites

tetron 22 Junior Poster

It is nice to have friends but as a programmer you should not see friend s very often. It doesn't want to be here.

It is allowed to have a class that has two rational numbers in it but you should probably give it another name:

if we go back to what a single rational number is

numerator/denominator

say

2/9

then if we had another rational number

3/11

it makes sense to
say

if(2.0/9 > 3.0/11)
{
std::cout << "first is bigger" << std::endl;
}

I have had to add the .0 to stop the int making both numbers 0

now the computer knows how to compare float and double and you know how to convert a single rational number to a double

class Rational
{
public:
Rational(int num = 0, int denom = 1);
double convert_to_double();
bool operator>(const Rational &r) const;
private:
int numerator. denominator;
]

this is a simplified class
now here note that Rational only can be set in the constructor

double Rational:: convert()
{
 double ret(numerator); //change numerator to 
 if(denominator > 0)
 {
    ret /= denominator;
 } 
 else
 {
    std::cout << "error denominator should not be 0!" << std::endl;
    ret = 0.0;
  }
return ret;
}

in main we want

// r1 = 2/9
Rational r1(2, 9);
//r2 = 3/11
Rational r2(3, 11);
if(r1 > r2)
{
  std::cout << "r1 is bigger than r2" << std::endl;
}

double d1 = …
tetron 22 Junior Poster

I missed that this was code that you were not intending to use but although in some ways it is clean code stay well away from it

it is using () to turn a struct into a class
rather than using a global or a static it does the silly n++ better would have been but still not my choice

/*fill a with the numbers 0-9*/
#include <iostream>
#include <vector>
int main()
{
int sz(10);
int a[sz];

//fill a using an int
//param three needs to be function pointer or ()
int i(0);
//i have not tested i++ as a function that is allowed
std::generate(a, a+10, i++); 
/*
going from first to last of a 
calling ++i;
*/

/* a for loop would be a minimal overhead and a better choice for now
*/

std::vector<int> vb;
vb.reserve(sz);
for(int j(0); j < sz; ++j)
{
vb.push_back(j);
}

//line 14 does the same as this
for(int k(0); k< sz ; ++k)
{
std::cout << vb[k] <<  " ";
}

//iterators would be faster



return 0;
}
tetron 22 Junior Poster

Hello Everybody,

int operator()() { return n++; }

yikes this is not a good idea to call a function without a name I don't think I have ever wanted to overwrite the operator() this is overloading a constructor in a class, change the name or use operator++ Generate although I haven't used it clearly calls g() several times. I guess it populates a using g()

Your code seems to use some very odd/scary choices what is it supposed to be doing?

if you are learning C++ use a class not a struct

if you need a unique number in a constructor there are better ways to do this.

if you are asking about g() your choice of line 14 seems to be unwise. Use code that has a clear intention or comment it. Although, it might seem the best solution now you will end up using different containers.

tetron 22 Junior Poster

First when you encounter a problem you should break it down it to small chunks. Therefore start with some very simple data.

is your code crashing or just not giving the output that you would expect?

As a rule it is not a good idea to use ofstream as a function parameter.

you should check is_open() before using the ofstream you have too many typedefs

It might be better to have

//#include <string>
std::string get_print_line();
bool print(std::string &file_dest, std::string &data);

I think your problem is Line 273
Link is still 0 you never set it anywhere it is tricky to follow some of your logic so I could well be missing other things.

another thing to look out for is that your pointers are not pointing to temporary variables.

tetron 22 Junior Poster

I haven't gone through all your code yet, and there are some dangerous bits of code that are probably not currently causing an issue.

If you have a function outside of a class it is best to pass in a variable to a function rather than access a global directly.

Then there are 2 options when you wish to set a variable one is to change it in the function and the other is to use a return type;

When you are saving n have you checked that the value is what you want.

A more sensible approach would be to use std::vector rather than v[10000] this makes your life easier

your sort selectie appears to be overwriting data before you are finished with it

A class more like this might help:

#include <vector>
#include <string>
class random_vector()
{
public:
random_vector();
std::vector<int> generate_vector(int lowest, int highest);
bool save_vector(std::string &file, std::vector<int> &vi);
std::vector<int> load_vector(std::string &file_name);
std::vector<int> sort_vector(std::vector<int> &vi);
};

the & is called a reference and lets you change a value inside a function

line 53 seems odd to be flipping the bool rather than setting it

by line 137 both vector & vectorS are the same as one another

Hi,

afisareVectorSortat(vector, vectorS, timeS, timeQS);

this would be better if you use more than one container especially one that is designed for the job such as vector. So that you have copies rather than just one vector. I would thoroughly check …

tetron 22 Junior Poster

Hi! it works! Thanks for helpin me! (^_^) I have one more question, why everytime I run the program and answer the "Your answer is: " it suddenly closed? is there something wrong with my code?

I did not read the logic correctly if
you change

final else:

else
{
  gotoxy(14,35);
  cout<<"Wrong!";
}
gotoxy(10,38);
cout<<"Play again?";
getch();
//add to end to delay instead of pause
char quit_c;
cout << "press any key to exit:" << endl;
cin >> quit_c;
cout << endl;
return 0;
}

there are a couple of issues with your code that should not be a problem but you have a set-up that is unfamilir to me.

It works when I run it on visual studio with some minor alterations but they won't fix your current error.

#include <iostream> //.h is for old c versions
#include <conio> //I don't actually use this

I have not used your positioning in the dos window
nor have i used getch() there is an obvious mistake in that you are marking
'a' as the correct answer but the answer is 'b'!

where you have

else if(ans == 'n')

you always still want to prompt for the answerso remove this line

I used endl in place of goto etc

std::cout << "who wants to be a millionaire" << std::endl;

you appear to have set-up that the std:: is default somewhere outside of the shown code so you wouldnt need it

tetron 22 Junior Poster

there are several issues that you are bringing-up which are not familiar to me. I have never used minGW. The only other option I can think of is to have a remote logon to the same computer so that the compiling is done for the same platform though again this is something that I have never set-up cross OS.

With the import libraries/dlls there obviously are going to be issues to be resolved but the purpose of a class is not necessarily going to be dependent upon its base classes. You can use simple interface versions of the .h to be switched over once the class is compiled and written.

You will not want to copy projects across just the source code. Now there will be code that will be identical irrespective of windows/linux.

- clearly you need to have a solution that can build on both platforms but this does not need to be the code you use on both systems.

Have a windows version and linux version of files for any specific code such as creating a window. The other files you can put in folders to be copied and SVN

Then you can integrate the code on the linux version to test that it builds with the dependencies added in.

tetron 22 Junior Poster

Here I need to use Graphics and mouse handling.. I'm totally new into Mouse programming in C++, still doing the coding with help of some online tutorials..

This is a question that seemed fairly easy to answer until I then looked at your code.

I take it that you are using an old version c++.

If not your OS is a graphical system such as windows. And you should use their built in handling of graphics for the mouse, etc.
and let us know.

Without it you need to be able to detect when the mouse button is clicked which probably requires interfacing with the mouse drivers which will get messy ...

You can still OO so that use say an unused char input to act as the mouse click for navigation to get that part working and then I am sure who ever set this task has told you how to access the mouse clicks.

tetron 22 Junior Poster

Your if s are going awry again
use {} every if , else if and else and many of your problems vanish without them if will only run until next ;

if(x == 1)
{//always use me
x = 3;
}//and me
else
{//here too
x = 4l
}//etc

Hi! I need help for my c++.

This is the code:

if(ans=='a' || ans=='A')
gotoxy(14,35);cout<<"Correct!";
gotoxy(10,38);cout<<"Get ready for the next round!";
else
gotoxy(14,35);cout<<"Wrong!";
gotoxy(10,38);cout<<"Play again?";

so

if(ans=='a' || ans=='A')
{
gotoxy(14,35);cout<<"Correct!";
gotoxy(10,38);cout<<"Get ready for the next round!";
}
else
{
gotoxy(14,35);cout<<"Wrong!";
gotoxy(10,38);cout<<"Play again?";
getch();
}
tetron 22 Junior Poster

NetBeans are we talking Java... ?

Most c++ code is platform independentant and linux implementations normally include use of codes that will work on both windows and linux, so this should be the end goal. That way the windows will be a bit harder but give you what you want in the long run.

Next general programming rules should be your ally here:

Sit down and work out what objects, classes and functions you need.

Some of the classes will e stand alone.
If you start off designing the .h files then you know what methods are available to the rest of your code

Then you each go off and write a separate area say one person does for example:
string_helper.cpp
and the other
number_helper.cpp

Then rather than test the whole project at once you should write a small test class:
test_string_helper.cpp
and then in a separate project check that there are no mistakes in the new code.
Then you can integrate the code together easily

there are open source - source control equivalent to source safe that allow project management but for two of you for a project that is only a couple of months old this is less important just make sure that you keep each other informed.

To build the project on windows - if it is c++ it should be relatively easy using Visual studio express - the danger is that …

tetron 22 Junior Poster

Your question highlights some gaps in your understanding in the statistics area. As phrased at the moment the answer is no it is not possible but perhaps you could be clearer.

The data structure just contain data and are mathematically approximately just vectors

i was wondering.
of all the data structures like list linked list,stack,queues,graph of bfs and dfs.
hashing,sorting,searching,arrays...heaps,

sorting is a specialised task and for a set problem you can probably beat the built behaviour.

A vector can be used with a statistical method and this is what makes matrices powerful.

It is a simple iterative process to implement approximate integration

i was wondering.
can anyone of them be solved using computational methods and statistic like
linear regression,quadratic regression,trapezoidal rule,simpson's rule..which is to improve accuracy of integral..

so what is confusing in your question is the use of the word solved any statistical method can be implemented but to solve a data structure does not make sense.

tetron 22 Junior Poster

I suspect what is happening is that your code is running too fast for you to see it then closes the window.

This will be down to how you are running the application

you can either run the .exe directly from dos or command shell in which case the window stays open or I think the command that is used is

system("pause");
return 0;

but I have never used it and it is a bad programming habit
there are other ways to delay the system

if you are using visual studio use ctrl + F5 to run your code instead of F5

otherwise for now you can add a cin>>var the reason for doing this is eventually you would want a more
robust system where you would be in a while loop.

int main(void)

don't use void as an argument

tetron 22 Junior Poster

If it is just an assignment to overload operators then you will probably get bonus marks for doing both.

However, this is not a question that can be fully answered in the abstract.

suppose we had a class like

class x_coord
{
public:
x_coord(int nx = 0);
bool operator>(const test_op &t) const;
int x;
}

the > is easy to define

but if you then have
a coord

class coord
{
public:
coord(int nx = 0, int ny = 0);
int y;
x_coord x;
}

how do you decide if one coord is greater than the other ?

this is the problem you have with classA and it is undefined
and your example suggests that

bool classA::operator>(const classA &c) const
{
  bool ret(false);
  if(stringA > c.getStringA())
  {
    ret = true;
  }
  else if(stringA == c.getStringA())
 {
    ret = (objectB > c.getObjectB());
  }
return ret;
}

but even this could be incorrect

as an abstract the > is undefined == is defined but cannot be used by sort
so for classB I would define all the operators if you have time and for classA only those that you know make sense +=, -=, ==

and if you are intending to sort classA you might want a clear understanding for classA behaviour

It is a flaw in your assignment that the class has not been given a clearly defined purpose and it is why your question is not easy …

tetron 22 Junior Poster

If you mean access to a folder from outside of your program this is not easy to achieve as it is your operating system that controls the folder, although you can probably stop a user writing to the folder detecting it from outside the OS as your program would be is tricky.

It is doable in windows but it is black hat behaviour to alter the pop-ups from explorer etc. If you are inside your code it is much more managable to control the user.

Try reading up on locking folders and if that doesn't achieve what you need you could try opening a new thread explaining why you need this behaviour and there might be a different solution.

Thanks, tetron.. What I want to achieve is this: If the program is running, once the user tries to access a folder specified as inaccessible by the program,a messagebox would pop up, stopping the user from doing so.

tetron 22 Junior Poster

With operator overloading just think of it as a function. You need to decide:

1 - do you need this function now?
2 - what is an appropriate name for what it does
3 - how to write the function
4 - is this the correct place to have the function
5 - do you need a test class to ensure that you have coded it correctly
6 - is a function that is unsed but makes sense with the object


The reason for considering these points is to keep your code maintainable. I assume that the answer to 1 is no or you wouldn't be asking.

With an overload 2 is answered for you and you have shown that you can do 3 and 5 if necessary

This leaves 4 & 6 and without knowing what you are trying to do

Does your class B want to be used directly with a < IF the answer is that you are not sure, you do not need to include it instantly.

You only have to implement a function when you need it. The overloaded operators are used for certain sort algorithms so it won't hurt to have one if it makes sense for the object.

what might need answering is your behaviour for class A what you want to happen with < or what is placed in your client code.

If you can be more …

tetron 22 Junior Poster

I am assume that the code that you have provided was a retype as it would not run. using namespace std; is the minor issue the bigger concern is that your if blocks are out of sync.

I would recommend that you always nest your if blocks with {} this protects you from making mistakes that are difficult to read

if(life==1)
cout<<"50-50"; 
cout<<"a. Files";
cout<<"c. Animals";
{

This if condition wants to run for just life == 1 so

if(1 == life)
{
cout << "50-50";
cout<<"a. Files";
cout<<"c. Animals";
}
else if(2 == life)
{
}

/*
//equivalent to what you wrote is
if(1 == life)
{
cout << "50-50";
}
//this will always run
cout<<"a. Files";
cout<<"c. Animals";
*/

You would also benefit a lot from having a question class
where you would need to track the
answer option_id
store 5 strings:
question
option_a
option_b
option_c
option_d

then you can add in your other methods

tetron 22 Junior Poster

I assume that you are asking this question for a windows system which won't let you create a directory from fstream so you need

#include <windows>
int main()
{
std::string folder("C:\\my_folder");
CreateDirectory(folder.c_str(), NULL);
return 0;
}

The Null is for the security settings which might let you lock the folder but I'm not sure whether you will be able to take control of the harddrive using legitimate means

Hi everyone. I am trying to write a program that controls access to my hard drive.i.e when this program is running, the specified directory can not be accessed. But first, s there any way one can create a folder using c++?

tetron 22 Junior Poster

Good that you have the project working but with xp the rel file path should be possible.
I though I'd mention this just in case you are having a problem that I encountered:

Are you using Norton Antivirus if so make sure that you disable their automatic recycle bin. It can break the MFT in a way that is only apparent to people who use fstream and could cause your problem

Only at startup, if I open the program manually the file is created fine, and I'm running Windows XP

In case anyone else every has this problem, a friend sorted me out and told me the problem lies in the fact that I was using relative paths as opposed to absolutes. Using GetModuleFileName() to find the absolute path solved this problem.

tetron 22 Junior Poster

>>aPure virtual function needs to be defined in the derived class
Not true. It does not have to be defined.

Apologies :$, I thought that the compiler complained you left out the definition completely.

tetron 22 Junior Poster

aPure virtual function needs to be defined in the derived class so

you parent needs to have a function called DOB etc that is the same signitaure as the virtual method.

class base1
{
publc:
base1();
virtual int get() {return 0;}
virtual int get_int() = 0;
}

class test1 : public base1
{
public: 
test1();
//must define virtual functions if = 0
virtual int get_int() {return 4;}
}
tetron 22 Junior Poster

Sorry, I 'm tired today should have been InitInstance

Thank You tetron.
But please be more clear with 'OnInIt()'I could not find it anywhere to override.
Can you tell me in which class I have override it?
You also spoke of this being the right choice or not,and so what other choices do I have?
I am new to this,so please help me out.

tetron 22 Junior Poster

I probably should not jump into a thread where so many people have ready jumped in but here goes...

You have a lot of posts but clearly there are somethings that have never quite grasped.

First what you have to understand is what a rational number is:
an integer is any whole number ie , 45, 678687, -23
and a rational number is one integer on top of another integer

ie 2/9 rather than the decimal 0.2222222

but if you set a float as 2/9 you would get the output to show 0.222

The idea is that you write a class to store the number

This is saying like, int, double, float you want to have something to store your number

in this instance your number say 3/7 needs to be stored in 2 parts
a numerator and a denominator
where here:
numerator would = 3
and
denominator = 7

so first as you cannot say
Rational r = 3/7;
as the compiler sees 3/7 differently from you
you have to tell the class how to load in the numbers

so you would have

r.numerator = 3;
r.denominator = 7;

and to display the number:

std::cout << r.numerator << "/" << r.denominator << std::endl;

but this would only work with numerator and denominator being public:

what is happening is each time you delcare a rational number a

jonsca commented: well done +2
PDB1982 commented: Thanks Very Much! You actually took the time to explain the topic to me, which makes this the greatest help I've ever received on this site. Thanks again! +1
tetron 22 Junior Poster

you would want two methods:

1st method get all of the sub strings of a length for each input

2nd method find the unique strings of a length

#include <vector>
#include <string>

class sub_string_counter()
{
public:
sub_string_counter();
std::vector<std::string> get_substrs(std::string & from,  int len);
int unique_strings(std::vector<std::string> &vs);
}

the function you need for 1 is .substr() you need the start and length parameters

//pseudo code
std::string input;
//do while start + length <= input.size();
std::string output = input.sub_str(start, length);
vs.push_back(output);

the next stage requires that you find the unique values in the vector

you can test the current string against all of the strings before it in the vector if not found
increase count
else
do nothing

sorry it was a mistake
for s = ccccc
no of distinct substrings are 5
and for s = ababa
its 9

tetron 22 Junior Poster

I am not sure that you necessarily want to use malloc or #define but there are a couple of obvious errors in your code

you have a size mismatch
DV is 4 double *
where as you try to set it to a random pointer of size 50;
What you should use is just a double *

like:

double * pd = new double[DIM];
//use the 
result[i][j].DV[0] = pd;

you should then use delele[] later on the pd;

I think that there are other issues about DV but basically a pointer
is it meant double * DV; ?

pointer can just point to the first element of an array and then store the size elsewhere. What is the struct supposed to be doing?

Dear all,
results[j].DV = (double(*)[DIM])

tetron 22 Junior Poster

I am rusty on this but as you say if hWind = 0
then you are using a method that requires a handle to a window if this is 0 it most likely means that you have not created a window successfully. So your new might not have created a window!

Another possibility is that you just need a method to get either ther current window or its parent without seeing context it is tricky to say for sure.

It would be helpful if you had included the code where m_hWind is called :)

Hi @ all, b4 things get The question is why since I create an instance of BERT_EVAL which is CTabPage based.

Thx in advance.
t.o.

tetron 22 Junior Poster

open is used by programs such as word which is multiple documents and what you are describing would require the intialisation method that could call open()

I think it is normally onInit() but you need to be confident that your design of saving the files this way is the right choice for your application

The class wizard places:

//TODO add your own intialisation here

method to be used and you would also need to associate your file extension to open with your .exe in you OS , I guess this must be windows as you are using the MFC

tetron 22 Junior Poster

the [] only work if string is defined

string has useful methods such replace()
find()

if you read up on the methods you will find cleaner solutions

but at first glance I think your error is here

output += alpha[t]

output[r] = alpha[t];

tetron 22 Junior Poster

You want to read up about game engines and you will find that there are several options that would allow you to start very quickly.

If you are using visual studio and windows the trickiest bit is creating the window and understanding what messages are about.

Now although versions of VISIO offer various resources that you can use to start it is important to be able to create the code without a built in resource if you wish to use Express editions as much of the resource editor is not present.

A good place to start on the learning of graphics is via online tutorials or scribble.

If you are using linux there are various other open source projects and physics engines that let you get started quikly but configuring the build options can be tricky as you have to link to every font used etc

tetron 22 Junior Poster

std::string is just a wrapper around a char * and from reading the function you do not want to change it back to char[] anyway

If you must you would still go via std::string str.c_str() converts a string back to the array pointer which is what you are doing when you don't set a size you set a char array1[] = "hello"; you have a pointer called array1

#include <string> // std::string
#include <iostream> //output
int main()
{
 //this is the same as char array1[] 
 char array1[] = "hello baby";
 std::string temp = array1;
 int first(0), last(5);
 char small_temp  = temp.substr(first, last - first);
 //write the string
 std::cout << "small_temp = " << small_temp << std::endl;
 char  array2[] = small_temp.c_str();
 return 0;
}

basically although you appear not to realise it you want to use a
std::string and if you need a char * or char [] just use a std::string with .c_str() function.

tetron 22 Junior Poster

If your string is just a std::string then your write methods are not taking advantage of the methods available to you .c_str() this converts a std::string into a char *

and .size() gets you the length of a string

therefore

std::ofstream fout("test.txt", std::ios::bin);
if(fout.is_open())
{
 fout.write(str.c_str(), str.size());
 fout.close();
}
tetron 22 Junior Poster

It is not constructive to keep posting what is effectively the same question in new threads. What you should do is work out what precisely you are trying to achieve and why?

If you feel that you have solved the first issue and moved on to the next mark the old threads as solved. But this would seem to be very similar to your last thread with NARUE pointing to the documentation.

Is this still related to you trying to solve a memory problem?

Hi ,,
I am using GetProcessMemoryInfo windows api to get
current memory usage by process..
It takes PPROCESS_MEMORY_COUNTERS pointer as argument.
I got value values in PPROCESS_MEMORY_COUNTERS structure
member after calling this api..

but what is the actual memory consumed by my process........
Is it Working set size or Page File Usage
which are the members of PROCESS_MEMORY_COUNTERS struct

Please help..

tetron 22 Junior Poster

First you have to show that you know what you want to achieve with your code. This might require pencil and paper.

The next step is to try and write a function that sorts the data this will be some kind of iteration and you need to work out what each step needs to show.

There are lots of techniques for sorting well but for now you just need to show that you can think through how to the problem. So show your first effort of what you think the function should look like. There are important concepts to learn by doing this task so it is important that you can think through the problem yourself.

ok thank you. i am new at this, how can i exatly sort this code?? i know im close but im still searching. could you help?

tetron 22 Junior Poster

Like with cin, every time you call it a pointer should advance to the end of the loaded data.


Here is a crude example of a getline which loads a line at a time
fstream works like iostream so the same methods can be used

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

int main()
{
std::string file_loc("test.txt");
//open the file upon creation of fin
std::ifstream fin(file_loc.c_str(), std::ios::in);


if(fin.is_open() == true)
{
 fin.close();
 int max_lines = 20000;//an arbitrary stop condition
 int count(0);
 while(count < max_lines) 
 {
   int max_line_length(1023);
   char line_array[max_line_length];
   fin.getline(line_array, max_line_length);
   //put the data into a string
  std::string line(line_arrray);

 /*
 proc line as you want in here
*/
   ++count;
 }
}
else
{
std::cout << "failed to open:" << file_loc << std::endl;
}
return 0;
}

how you want to load and handle the data is up to you but as a beginner dealing with strings is easiest if you are using data of unfixed length and might want to change the design.

But you could store a list of values and load as binary file instead but your format of your load must correspond tyo your save