mitrmkar 1,056 Posting Virtuoso

error: cannot convert ‘std::string’ to ‘const char*’ for argument ‘2’ to ‘int mysql_query(MYSQL*, const char*)'

That says that you cannot pass a std::string to the mysql_query(). Since it expects a const char * , you need to use the .c_str() method, so simply change to;

mysql_query(conn, queryText.c_str());
mitrmkar 1,056 Posting Virtuoso

There is a very basic problem that you have in main(). Now if you go through it carefully, you'll notice that there are float Mean and float MeanValue trying to serve the same purpose.

mitrmkar 1,056 Posting Virtuoso

Please explain what you mean by Tag before you post, this is my first time so I have no clue in what Im doing today.... LOL

Well, adnan.siddique tried to say that use code tags when you post code. That will preserve the code formatting making it readable. As you can see, niek_e added the code tags to your post and now it looks good.

Scroll up to your first post and click the link that reads "Help with Code Tags".

mitrmkar 1,056 Posting Virtuoso

You posted the wrong typcast -- should have been LPWSTR,

I think you maybe misunderstood what I was saying and maybe I'm not quite getting what you are saying .. but anyway.
Having UNICODE defined and doing a LPCWSTR typecast results in

LoadLibraryW((const wchar_t *)"test.dll"); // This will NOT work

And that is actually what was the problem here.

The (LPCTSTR) cast, that I posted, is actually extraneous and can be removed. However, if there is to be a cast, it has to be (LPCTSTR), not LPCWSTR (given that LoadLibrary() macro is used instead of the actual functions).

mitrmkar 1,056 Posting Virtuoso

I've changed LoadLibrary((LPCTSTR)("test.dll")) to LoadLibrary((LPCTSTR)("C:/Users/Nicholas Roge/Desktop/test/test.dll")), however there isn't any luck. Unless I misunderstood what you were telling me to try, however.

Have you UNICODE defined?
If so, then the following cast

LoadLibrary((LPCTSTR)("test.dll"))

causes this behaviour. The end result is that a non-UNICODE string gets passed to LoadLibraryW() and that will not work.

To fix it, change it to

LoadLibrary((LPCTSTR)_T("test.dll"));

You need to also #include <tchar.h>

mitrmkar 1,056 Posting Virtuoso

Shouldn't you fix those if statements to be like ...

if(isGet == 0)
mitrmkar 1,056 Posting Virtuoso

The declaration of class CBaseAnimating is missing a semicolon.

mitrmkar 1,056 Posting Virtuoso

Unless I'm missing something line 12 sets the value of sz to 1 Gig. All that line does is initialize str to the first sz bytes of memblock.

The OP is trying to get a brand new std::string in;

std::string str(memblock, sz);

containing a copy of the data that was read in, so that would double the size of the allocated memory.

mitrmkar 1,056 Posting Virtuoso

A few quick notices,

1) These two are declared and used, but not implemented
bool operator==(const matrix &);
bool operator!=(const matrix &);
The code should not actually compile because of that, isn't your compiler saying anything?

2) There is no copy constructor i.e. matrix(const matrix &) , you absolutely need one, because of ( matrix (*this) ) . Now you are using the compiler-generated copy constructor, which causes you to delete memory twice in the destructor.

3) avoiding self-assignment
Now you have

if (!(*this==in))

however, that checks for equality, not self-assignment. One way to do that is

if (this == &in)
    return *this;

For some more advice, see C++ FAQ

4) There is an extra semicolon; if ((row!=in.getRows())||(column!=in.getColumns())); Once you get those things in order, you might post back with the revised code.

In general, yet a couple of major things to think of:
- managing throw/catch()
- resizing of a matrix wrt. memory corruption/leaks

mitrmkar 1,056 Posting Virtuoso

>>Since you are trying to allocate rather huge amounts of memory (2GB),

Nope. Its only 1 Gig which is less than what st::string.max_size() returns.

Actually the OP tries to get ~2 GBs .. I think you missed ...

std::string str(memblock, sz); //too much for visio :(
mitrmkar 1,056 Posting Virtuoso

error C3379: 'Form1::Form2:: DoubleBufferPanel' : a nested class cannot have an assembly access specifier as part of its declaration

Move the DoubleBufferPanel class outside your Form class i.e.

#pragma once

namespace Form1 { // <- You might have another namespace here
 // the usual 'using ...' stuff follows
 using namespace System;
 // etc ...
 // Next your new class ...
 public ref class DoubleBufferPanel : public Panel
  {
  public:
    DoubleBufferPanel(void)
    {
        this->SetStyle(ControlStyles::DoubleBuffer
         | ControlStyles::UserPaint
         | ControlStyles::AllPaintingInWmPaint,
          true);

        this->SetStyle(ControlStyles::DoubleBuffer, true);
        this->UpdateStyles();
    }
  };
 // Followed by the original code ...
 public ref class Form1 : public System::Windows::Forms::Form
 ...
mitrmkar 1,056 Posting Virtuoso

This should do ..

public ref class DoubleBufferPanel : public Panel
  {
  public:
    DoubleBufferPanel(void)
    {
        this->SetStyle(ControlStyles::DoubleBuffer
         | ControlStyles::UserPaint
         | ControlStyles::AllPaintingInWmPaint,
          true);

        this->SetStyle(ControlStyles::DoubleBuffer, true);
        this->UpdateStyles();
    }
  };
mitrmkar 1,056 Posting Virtuoso

I appear to have hit a memory limit in visual studio.

Since you are trying to allocate rather huge amounts of memory (2GB), I'd guess that the limitations are more probably imposed by your operating system (which one is it?) than the std::string implementation.

See MSDN documentation on Memory and Address Space Limits. Are you perhaps reaching the 2GB user-mode virtual address space limit there?

PS. As already suggested, perhaps process the file in much much smaller chunks than what you are now planning.

mitrmkar 1,056 Posting Virtuoso

the program seems to ignore the getline part? why doesnt it work?

I'd suspect that openWP.seekg(20*wordnum, ios::beg) causes that to happen. If you seek to a position that's out of range, then getline() will fail.

You can see it for yourself by adding some output, for example

// snip ...

openWP.seekg(wordnum, ios::beg);
string wordset="yes?";

getline(openWP,wordset);

// what is the state of the stream?
cout  << boolalpha 
        << "openWP.eof() = " << openWP.eof() << endl
        << "openWP.bad() = " << openWP.bad() << endl
        << "openWP.fail() = " << openWP.fail() << endl;

Then the return statement is definitely wrong, you can return only a single value from a function, so change to

// return the word ...
return word;
mitrmkar 1,056 Posting Virtuoso

Is there a code for a long long int ?

C99 standard says %lld and %I64d accepted at least by Microsoft and MingW/GCC.

mitrmkar 1,056 Posting Virtuoso
warning: format %d expects type int, but argument 3 has type __off_t

Change %d to %ld . That'll most probably fix it, %ld tells that the argument will be long int . If the warning persists, post back.

[EDIT]
Badly beaten by AD it seems, though I'm still in favour of trying %ld

mitrmkar 1,056 Posting Virtuoso

Aren't you doing something illegal at line 25 ?

mitrmkar 1,056 Posting Virtuoso

i am not able to figure out when i write definition for my increment operator ++.....how it would change car[bashed]???

Sorry but I don't get what you are saying. Could you describe it in more detail?

mitrmkar 1,056 Posting Virtuoso

So does anyone know of how I should edit stdafx.h to get his program to work?

Unfortunately editing stdafx.h will do no good. It is a MFC program you have there, and the VC Express won't be able to compile it like jonsca ^said^.
If you know someone, who's familiar with the MFC, the program might be quickly converted to a Win 32 GUI application, after all it appears to be a small'ish dialog-based program.

mitrmkar 1,056 Posting Virtuoso

You have to move the int Banger::objectCount=0; to the the banger.cpp file.

mitrmkar 1,056 Posting Virtuoso

recently alot of my programs have been giving compiler errors because i failed to put a 'const' when needed =.=||

Perhaps read Const correctness

mitrmkar 1,056 Posting Virtuoso

the compilers says "passing 'const name' as 'this' argument of 'std::string name::get()' discards qualifiers"

I was just curious about the error message your compiler gives, anyway GCC gave a more sensible/straightforward message;

error: no matching function for call to 'name::get() const'

implying that it expects the get() member function to be const .


You could certainly add 'const correctness' to the program and figure out all the places where it is best to use const references;

// Not like this ...
bool operator<(name a, name b);
// but instead like this ...
bool operator<(const name & a, const name & b);

[EDIT]
Beaten by jonsca it seems ...

mitrmkar 1,056 Posting Virtuoso

i have trouble trying to display the name of the contacts. p->first.get()

What is the error message your compiler is giving?

mitrmkar 1,056 Posting Virtuoso

Maybe I posted in the wrong spot I am sorry. I thought this was a place for the amateur to ask questions, which I am. I am trying to learn.

I think there's no need for you to be sorry, i.e. while you are learning you can always post questions here.

PS. On a side note, after having read your first post, I was under the impression that you are actually a programmer hired by a company struggling with this problem. I (and probably many others too) was astonished by that, but now I know better.

mitrmkar 1,056 Posting Virtuoso

I guess I am really having trouble with what's inside the function How do I get it out..

You get it out by passing it in in the first place. So for example

struct theThing
{
    int ThingYesNo;
    double ThingHeight;

    // zero-initialize the member variables
    theThing() : ThingYesNo(0), ThingHeight(0)
    {}
};

// theThing is passed in by reference, so you can modify it
// and use later on ...
void theThingFunction(theThing & t)
{
        do
    {
    cout <<"Does the thing exist?"<<endl;//d11
    cout << "1) Yes" <<endl;
    cout << "0) No" <<endl;
    cin>> t.ThingYesNo;

        if (t.ThingYesNo==0)
            break;
        else 
        {cout << "What is the Things Height?"<<endl;
        cin>>t.ThingHeight;
        }

    }while (t.ThingYesNo !=1);
}

int main()
{
    theThing t;
    theThingFunction(t);
    // here you can access what's stored in the 't'

    return 0;
}

There are other alternatives for this, like passing a pointer to the function, or allocating (using operator new) a theThing struct inside the function and returning a pointer to it. Anyway, the above should do 'the thing' that you are looking for.

[EDIT]
Expanding a little on how you can do the same without using a struct.
You can also pass by reference/pointer the individual variables into a function,
so that would change the function's signature to

// Arguments passed by reference
void theThingFunction(int & ThingYesNo, double & ThingHeight);

// and use it like ...
int ThingYesNo = 0;
double ThingHeight = 0;
// call the function
theThingFunction(ThingYesNo, ThingHeight);
mitrmkar 1,056 Posting Virtuoso

I'm guessing that initgraph() fails there and the program just silently exits (i.e. calls exit(1)).

[EDIT]
After looking up initgraph() it's clear that the teacher gave you a bad example (perhaps intentionally?). Anyway, you have to change the call to initgraph() so that it matches the function's signature.

mitrmkar 1,056 Posting Virtuoso

But my my application is a Win32 application, it shouldn't matter, no?

By reading your first post I got the impression that you are having 64-bit libraries etc and trying to get them working with VC Express, that would not work. Perhaps I understood it all wrong?

mitrmkar 1,056 Posting Virtuoso

I've added the .lib and header files under Project->Linker Dependencies and Project and Solutions->VC++ Directories (where I added library files for x64 and header files) but still nothing.

As far as I know Visual Studio 2008 Express Edition does not support 64-bit programs. However, by installing the correct Windows SDK you'll get the 64-bit tools enabiling you to compile/link from the command line. And possibly with extra tweaking you even can get the tools to integrate with the IDE.

Anyhow, you might want to ask these kind of questions on a Microsoft's dedicated Visual C++ Express Edition forum.

Note though that you may end up doing a whole lot of installing/uninstalling and reading of the various Readme files to get the things working.

mitrmkar 1,056 Posting Virtuoso

Since it is a null pointer assignment, you might be able to start finding out the cause(s) of the crash using assert() .
So, for all your pointers wherever used, do: assert( the_pointer != NULL ); Likewise, add sanity checks, so that you will not allocate zero-length strings, i.e. assert( size_to_alloc > 0); (also remember to delete [] the memory you allocate).
Then switch the usage of sprintf() to snprintf() AND check whether the data was truncated or not.

One thing to fix for sure is the first strcpy() you have there ( strcpy(prec,"^/*+-") ), it is a guaranteed buffer overflow, you need a larger buffer there.

Maybe the above helps to track down the problems.


However, I'd suggest that you completely switch from C to C++, i.e. use string, stringstream, getline() et al, everywhere. It would be could practise for you, I think.

mitrmkar 1,056 Posting Virtuoso

Is there a way to convert a String variable to char []?

I pretty much missed the fact that this is about Borland's String class.
In that case the looping over the string and copying it byte by byte using the [] operator won't work.

If you want to stick with char fileName[100] then you can use e.g. strcpy()/strncpy() together with the String's c_str() method.

However, wouldn't it be easiest to change the type of fileName to String , so you could do a simple assignment, instead of hassling with C-style strings.

PS. The order of the posts in this thread is odd ... let's see where this one lands.

mitrmkar 1,056 Posting Virtuoso

Just pass the vector by reference, so you will have

int solveMaze(int x,int y,vector< vector<char> > & maze,int size);
mitrmkar 1,056 Posting Virtuoso

char fileName[100] = "unsaved.txt"

OK, what you have there seems like the right way of doing it, as long as newFileName.Length() does not exceed the buffer size. Just a suggestion, to simplify the code a little bit;

// also fileName is of type String ...
String fileName = "unsaved.txt";

// and ...
String newFileName = fileNameEdit->Text + ".txt";
rename( "unsaved.txt", newFileName.c_str() );
fileName = newFileName;

Regarding the crash (what kind of crash actually?), have you run the program in the debugger to see at which line it crashes?


[EDIT] Hmm, the post I'm replying to appears below this one.

mitrmkar 1,056 Posting Virtuoso

How is the fileName actually declared?

mitrmkar 1,056 Posting Virtuoso

How come? I thought that when I define my own constructor, the default constructor isn't created.

The constructor you've written also happens to be a default constructor (i.e. constructor that can be invoked without arguments), and would be automatically invoked if you'd simply delete the line 32.

mitrmkar 1,056 Posting Virtuoso

I meant what is wrong. It is not displaying the no of elements in the array?

In the main() function, you have

cout << countElements (a,MAX);

What will it print, if you don't specify any return value in countElements() ?

mitrmkar 1,056 Posting Virtuoso

I am able to compile. Which value?

Well it's up to you, but wouldn't it be suitable to return the number of elements in the array?

mitrmkar 1,056 Posting Virtuoso

You can also simply delete the line 32, otwarte_okna gets constructed via the ListaOkien default constructor automatically.

mitrmkar 1,056 Posting Virtuoso

You have forgotten to return a value from the countElements() function. Isn't the compiler saying anything about that?

mitrmkar 1,056 Posting Virtuoso

Why does scanf("%d %d"+2) become scanf("%d") ?

Would the following be of any help?

#include <stdio.h>
int main(void)
{
    char const * p = "invisible text" + 10;
    printf("%s", p);

    return 0;
}
mitrmkar 1,056 Posting Virtuoso

Obviously... Forgive my ignorance, but is that standard? I can't find anything in cplusplus.com's reference docs that indicate it's standard. There is absolutely no reference to const, and the examples don't have it either.

After staring at the C++ draft standard (for some time), the most relevant part that I found, says;

Compare is used as a function object which returns true if the first argument is less than the second, and false otherwise. Compare comp is used throughout for algorithms assuming an ordering relation. It is assumed that comp will not apply any non-constant function through the dereferenced iterator.

So it appears to be suggested to have it done as in e.g. GCC.

As a side note, if I compile using MinGW in Dev-C++ I get the same error you posted. ...
I think that's the same implementation Code::Blocks uses isn't it?

Possibly yes, perhaps different version though.

mitrmkar 1,056 Posting Virtuoso

Why would the const make a difference?

The compiler's implementation of the STL requires it.

mitrmkar 1,056 Posting Virtuoso

However, when you consider that VC++2008 is standards-compliant and that 2 of us have successfully compiled it with VS2008, the opposite seems to be the situation here. It appears that he's attempting to compile modern code with an outdated compiler.

In this particular case, VS 2008 is the one that is more 'relaxed'. One good place to figure out whether a given piece of code really is standards-compliant, is Comeau's online service. You can check it out at Test Drive Comeau C++ Online.

mitrmkar 1,056 Posting Virtuoso
bool sortByName(tropical &t1, tropical  &t2);

sort (fruitlist.begin(), fruitlist.end(), sortByName);
//problem!! gives me rubbish errors when compiled. could it be compiler problem??

GCC 4.4.0 says; stl_algo.h:124: error: invalid initialization of reference of type 'tropical&' from expression of type 'const tropical' meaning that you need to change to:

bool sortByName(const tropical &t1, const tropical  &t2);

With regard to this, when trying out the example snippets found on e.g. internet, be prepared that they may be outdated i.e. a relatively recent/standards-compliant compiler will reject the code while others happily compile without a hitch.

mitrmkar 1,056 Posting Virtuoso

If it is CString as in MFC, then CString has methods like, Find(), FindOneOf(), Left(), Right() and Mid().

mitrmkar 1,056 Posting Virtuoso

however the cin doesn't seem to be working - I'm getting the initialised value of 0 for n no matter what I enter.

That's because you are passing n by value. You need to pass it by reference instead, i.e.

double gauss(fun f, double a, double b, int & n)
{
    cout << "\n********** GAUSS QUADRATURE **********"<< endl;
    cout << "For the equation f(t) = t^2" << endl;
    cout << "Enter the quadrature order, n you wish to use: " << endl;
    cin >> n;
    cout << "Enter the interval of integration, [a,b]: " << endl;
    cin >> a >> b;
}
mitrmkar 1,056 Posting Virtuoso

So I can use API commands without having to start a new "Win32 Project". I can use them if I'm using Win32 Console App?

You need to #include <windows.h> and then you can. Depending on what API functions you end up using, you may have to link with additional libraries.

Anyway, a simple example,

#include <windows.h>
int main()
{
    // testing ...
    return ::MessageBox(NULL, "Says hello", "Console", MB_ICONINFORMATION);
}

Be warned though, that you might be spending quite some time to get the thing working - trying to say that Windows programming is not actually 'easy'.

mitrmkar 1,056 Posting Virtuoso

what I have done wrong?

To point out basic errors, see the comments below

#include<iostream>
#include<vector>
#include<cmath>
#include<iomanip>

using namespace std;

class tabledata {
    private:
        long double abscisass[28];
        long double weights[28];
    public:
        void set_values();
}  

// a global variable here, will you be using it? If not, delete it.
table;   

void tabledata::set_values () {

    // Both arrays are of size 28 -> the last index
    // you are allowed to use is 27, NOT 28

    abscisass[28] = 0.9739065285171717200779640;
    weights[28] = 0.0666713443086881375935688;
}

int main()
{
    // Here you have two uninitialized arrays
    long double abscisass[28], weights[28];

    // The variable name 'table' clashes with the one
    // you already have as a global variable, 
    // do something about it.
    tabledata table;
    table.set_values();

    // Here you illegally (again out-of-bounds) access the 
    // still-uninitialized 'weights' array local to this function.
    // Shouldn't you be using the 'table' instead?
    cout << "the answer is " << setprecision(25) << weights[28];

    return 0;
}
mitrmkar 1,056 Posting Virtuoso

I wrote the program as a console app that asked for user inputs, but I need to make it with dialog boxes now. Therefore, I pretty much have to start from scratch and use Win32 API.

It's doable to have a console app using dialog box(es), so starting from scratch writing a full-blown Windows app is not really obligatory. You can use the DialogBox() API for example, as mentioned above. I gather there are several examples of this available, if you search sites like codeproject etc.

mitrmkar 1,056 Posting Virtuoso

That's good to hear. But after all, maybe it still would be better to put the game aside for some time, and learn how to use functions/structures instead. What do you think? This is just to say that don't overdo yourself with a single function consisting of several hundreds of lines of code.

mitrmkar 1,056 Posting Virtuoso

A basic tutorial that might come in handy is theForger's Win32 API Programming Tutorial.