mitrmkar 1,056 Posting Virtuoso

A radical suggestion, instead of coding the games inside the switch, make the games functions and do something like

while(1)
{
    cout << "A: To Play the number guessing game." << endl;
    cout << "B: To Play the letter game." << endl;
    cout << "C: To quit program." << endl;
    cin >> choice;	

    switch (choice) 
    {
        case 'A': case 'a': // number guessing
            number_guessing();
        break;
        case 'B': case 'b': // letter game
            letter_game();        
        break;
        case 'C': case 'c': // exit
	    return 0;
        default:
	    cout << "Correct choice please ...\n";
        break;
    }
}

Or perhaps use if/else if/else ... instead of switch() .

mitrmkar 1,056 Posting Virtuoso
...
double CelsiusToFahrenheit(double c);
...
int main()
{
...
}

double CelsiusToFahrenheit(double c) ; // <- remove the semicolon
{
	return (9.0 / 5.0 * c + 32);
}
mitrmkar 1,056 Posting Virtuoso

Well, you get this code with copy/paste from Miscrosoft support site:
http://support.microsoft.com/kb/139652

So it seems to be ...

I think, it's not so interesting work to debug Microsoft official code examples on the forum...

I would actually like to know what goes wrong with that piece of code, (especially considering it is a simple MSDN example)

mitrmkar 1,056 Posting Virtuoso

Try not to use the goto , have you considered using break instead

for(int i=0; i<10; i++) {
 if (i > 0)
  break;    // <- breaks out of the for loop ...
else
  cout << i;
}
OmniX commented: Thanks for the help +1
mitrmkar 1,056 Posting Virtuoso

Couldnt compile code:

ERROR:
Vector3.cpp||In function `int main()':|
Vector3.cpp|9|error: brace-enclosed initializer used to initialize `std::string'|
Vector3.cpp|9|error: brace-enclosed initializer used to initialize `std::string'|
Vector3.cpp|9|error: brace-enclosed initializer used to initialize `std::string'|
||=== Build finished: 3 errors, 0 warnings ===|

Oops, my bad, use ...

std::string inputs[3]  = {"1,2,3", "4,5,6", "7,8,9"};
mitrmkar 1,056 Posting Virtuoso

Why is the stringstream initialized within the forloop instead of outside?

That way you automatically get a 'fresh' stringstream object meaning that you don't have to take care of resetting it in any way.

mitrmkar 1,056 Posting Virtuoso

If I try using that while loop more than once, its useless as it is bypassed and keeps using the old values stored in the variables and dosent take in the seperate the new values.

Hmm .. I'm not quite sure what the actual problem is, but maybe the following helps to understand things (It's a modified version of what niek_e already posted)

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()
{
    // 3 strings as input
    string inputs[3]  = {{"1,2,3"}, {"4,5,6"}, {"7,8,9"}};
    string buffer;
    int integer;

    // iterate through the 3 input strings ...
    for(int ii = 0; ii < 3; ++ii)
    {
        stringstream ss;
        // store the input string in the stringstream
        ss << inputs[ii];

        // extract and cout the numbers one at the time ...
        while (getline(ss,buffer,','))
        {
            // convert to an int
            istringstream strin(buffer);
            strin >> integer;

            cout << integer;
        }
    }

    cin.get();
    return 0;
}

Output is ...

123456789
mitrmkar 1,056 Posting Virtuoso

I'd say it should work as such.

So, the next step might be adding more error checking wherever applicable. I.e. verify that StartDoc/StartPage/EndDoc/EndPage return a value greater than zero, if not, use GetLastError() to get the error code. Also check that TextOut() is not returning FALSE .


[EDIT]
Since you seem to have trouble with the code tags, read http://www.daniweb.com/forums/misc-explaincode.html

mitrmkar 1,056 Posting Virtuoso

The InitDocStruct() function seems OK to me. So the problem probably is in the actual printing code you have.

mitrmkar 1,056 Posting Virtuoso

#include <winresrc.h> in the .rc file, that way the definitions of e.g. DS_MODALFRAME and WS_POPUP will be known. In addition to that, add #define IDC_STATIC -1 in the resource.h file.

mitrmkar 1,056 Posting Virtuoso

'This is a test'. When you save it and then open it in notepad, this is what it looks like:

{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fnil\fcharset0 Arial;}}
\viewkind4\uc1\pard\fs20 this is a test\par
}

see? a whole lot of crap is added to the text file. How can I fix this?

The content is in Rich Text Format (RTF). Notepad does not understand it and hence displays it raw. Open the file with e.g. MS Word, and you'll see what you expected.

mitrmkar 1,056 Posting Virtuoso

I deleted it and got more errors.

What is your compiler and what are the errors?

mitrmkar 1,056 Posting Virtuoso
#include<iostream>
using namespace std;
int main()  // <- This line simply just MUST 
            // NOT be here .. there is no way around it
mitrmkar 1,056 Posting Virtuoso

by that I mean I added the DLL's path to the additional dependencies directory...?

PATH does not mean the 'additional dependencies directory'. Windows searches for the .dll at run-time as specified in Dynamic-Link Library Search Order

PS. You can check your PATH environment variable simply by typing PATH in a command prompt, every path displayed by the command will be used for loading .dlls.

mitrmkar 1,056 Posting Virtuoso

First of all, please use code tags when you post your code.

You have an extra curly brace there ...

// }  <- extra curly brace here
~Quadrilateral() // Call Destructor
{
    cout << "\n\nThe Base Class Rectangle has been destroyed!" << endl;
};

[EDIT]
Oh well, niek_e got there first ...

mitrmkar 1,056 Posting Virtuoso

How about managing the id in the Base class, i.e.

class Base
{
    public:
        explicit Base() : id(object_count++) {}
        static int object_count;
    protected:
        int id;
};

int Base::object_count = 0;

class child: public Base
{
    public:
        child(int val){}
};
int main()
{
    child c(1);
    return 0;
}
mitrmkar 1,056 Posting Virtuoso

just shows last student records ten time instead of each student .

Isn't that quite obvious if you take a close look at the loop,

for(k=1;k<=10;k++)
{
    // do this ten times ...

    // ask the user for the file name <-> shouldn't you 
    // open the file before this loop?
    scanf("%s",filename);*/

    // open the file, start reading from the very beginning
    fp=fopen("filename","r");
    
    // grab the information ...
    fscanf(fp,"NAME= %s\tCOURSE ENTITLLED= %s\t ID NUMBER= %d\t DATE OF BIRTH= %s\tAVERAGE= %f\n",name,course_enrolled,&id_number,date_of_birth,average);

    // and display it ...
    fprintf(stdout,"NAME= %s\tCOURSE ENTITLLED= %s\t ID NUMBER= %d\t DATE OF BIRTH= %s\tAVERAGE= %f\n",name,course_enrolled,id_number,date_of_birth,average);

    // now close the file <-> shouldn't you close the file after this loop?
    fclose(fp);
}
mitrmkar 1,056 Posting Virtuoso

Print Dialog is not shown

That is because you specify the PD_RETURNDEFAULT flag, for details see

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

mitrmkar 1,056 Posting Virtuoso

I think the library you need is libcomdlg32.a.

Generally, when you get linker errors related to Windows API functions, lookup the function's documentation in MSDN, scroll down to the bottom of page where you can find the name of the required .lib (i.e. in this case: Import library Comdlg32.lib). That gives you enough information to map the Win .lib file to the Dev-Cpp's counterpart.

mitrmkar 1,056 Posting Virtuoso

Futhermore, you have the variables the wrong way around, i.e. instead of a >> strin; use strin >>a;

Nick Evan commented: Duh... Missed that completely +8
OmniX commented: Thanks for the help +1
mitrmkar 1,056 Posting Virtuoso

Any guidance on how to polish this code up would be greatly appreciated.

The code needs proper, consistent indentation.

Salem commented: It certainly does! +19
mitrmkar 1,056 Posting Virtuoso

Shouldn't you be using pi2->pDevMode->dmFields = [B]DM_ORIENTATION[/B]; instead of pi2->pDevMode->dmFields = DM_PAPERSIZE;

mitrmkar 1,056 Posting Virtuoso

You might use stringstream ...

#include <vector>
#include <string>
#include <sstream>
using namespace std;

int main()
{
    int a = 1;
    int b = 2;
    int c = 3;
    int d = 4;
    int e = 5;
    int f = 6;

    vector<string> abcd;
    stringstream sstrm;

    sstrm    << a << " " 
             << b << " " 
             << c << " " 
             << d << " " 
             << e << " " 
             << f;

    abcd.push_back(sstrm.str());

    return 0;
}

Note that vector has no append() member function, see vector reference

mitrmkar 1,056 Posting Virtuoso

i did. thats all i am using to find the mouse position. Is it completely right? :O

You might change it to

int xPos = GET_X_LPARAM(lParam); 
int yPos = GET_Y_LPARAM(lParam);

although that probably won't fix anything. Anyway, I meant that you might perhaps post the complete code you have for drawing the line.

mitrmkar 1,056 Posting Virtuoso

I am using DEV C++. Do I still need to link to libwinspool.a.

Yes, to link with libwinspool.a, open the Project/Options/Parameters tab, click Add Library or Object and browse for that library.

mitrmkar 1,056 Posting Virtuoso

But I am getting linker error.
" [Linker error] undefined reference to `OpenPrinterA@12' "

You (may) need to #include <winspool.h> If you are not using a MS compiler, you need to link with libwinspool.a, otherwise winspool.lib.

mitrmkar 1,056 Posting Virtuoso

sorry that doesn't work. I am trying to draw a line from where my mouse is when i click to where it is when i let go, if that helps. if i do it at 0,0 its fine but as i go further across and down the line isn't where my mouse is any more, it gets further and further away :(

You might post the code.

mitrmkar 1,056 Posting Virtuoso

Apparently, calling TTF_Quit before TTF_CloseFont will cause the error. Is there any easy way around this?

You might also consider using atexit()

mitrmkar 1,056 Posting Virtuoso
mitrmkar 1,056 Posting Virtuoso

Obviously you don't have a class named CMyView , so you cannot use the provided example as is. Instead you could e.g. make the provided example a stand-alone function and use it as such, i.e. simply

BOOL GetPageSize(CSize &nRetVal)
{
    // rest of the example code here ...
}
mitrmkar 1,056 Posting Virtuoso

error C2511: 'Contributor::Contributor(std::string,double,Contributor::gender,int)' : overloaded member function not found in 'Contributor'
see declaration of 'Contributor'

In the class declaration, you probably meant to have a member variable like gender Sex; instead of enum gender;

mitrmkar 1,056 Posting Virtuoso

I have read about Object Serialization in my JAVA book. Could it be possible with C++?

See e.g. here

Prabakar commented: thanks +1
mitrmkar 1,056 Posting Virtuoso

The function is malloc() , not maloc().

mitrmkar 1,056 Posting Virtuoso

if have what should i do??

Erm, delete the text log.h (a header file) , leaving the curly brace inplace.

mitrmkar 1,056 Posting Virtuoso

Please, use code tags when you post code.

See the comments ...

double getdaysmissedavg(int num_employees, int days_missed)
{
	int numemployees=0;
	int daysmissed=0;
	double daysmissedavg=0;

        // every time you call this function, you effectively calculate 
        // '0/0' which results in error (you must not divide by zero)
        // shouldn't you be using this function's parameters instead??
	daysmissedavg=numemployees/daysmissed;
	cout<<"Calculate the average number of days absent "<<daysmissedavg;

	system("pause");

        // then you'll probably want to return the calculated value
        //  'daysmissedavg' instead of zero ...
	return 0;
}
mitrmkar 1,056 Posting Virtuoso

Do you really have the following line as is in the code? } log.h (a header file) If you do, then there's the error.

mitrmkar 1,056 Posting Virtuoso

I have written the below code to create a modaless dialog.what to do to view the dialog?it just blinks and goes away...

combodlg cd= new combodlg(this);
	 	cd.Create(IDD_DIALOG1, this);
		cd.ShowWindow(SW_SHOW);

The constructor of the dialog can be like

combodlg::combodlg(CWnd* pParent /*=NULL*/)
{
    VERIFY(Create(IDD_DIALOG1, pParent));
}

and to use the dialog ...

combodlg * pcd = new combodlg(this);
pcd->ShowWindow(SW_SHOW);

and lastly, override PostNcDestroy() ..

void combodlg::PostNcDestroy() 
{
    CDialog::PostNcDestroy();
    delete this;
}
mitrmkar 1,056 Posting Virtuoso

I'm pretty sure that exists too.

I also love this one (not sure if its in Windows API or DirectX):

#define 1 TRUE
#define 0 FALSE

Actually it would be

#define TRUE 1 
#define FALSE 0
mitrmkar 1,056 Posting Virtuoso

i have to add only one line at a time.what i need is add he item in second dialog to first dialog's combo box as soon as I hit "Add" button each time.

You might change the second dialog's constructor to take e.g. a pointer to the first dialog's CComboBox and then use that pointer to add each item in the second dialog i.e. something like

// in the first dialog box ...
// Pass in the address of the combobox (m_selcam) ...
Add cd(NULL, &m_selcam);
cd.DoModal();

/////////////////////////////////////////////
// in the second dialog box ...
...
GetDlgItemText(IDC_EDIT2,str_name);
// m_selcamPtr is a pointer to the combobox 
// received via the dialog box's constructor
m_selcamPtr->AddString(str_name);
...
mitrmkar 1,056 Posting Virtuoso

how do i use it ?

see here

mitrmkar 1,056 Posting Virtuoso

Generally you use the MAKEINTRESOURCE macro to convert the resource id. However, the createStream() probably isn't capable of playing a resource.

mitrmkar 1,056 Posting Virtuoso

if possible cud u provide me with some links.

Basic file I/O

Googled
odbc c++ wrapper

mitrmkar 1,056 Posting Virtuoso

Define _WIN32_WINNT before you #include <windows.h> As to the reason why you need it, see Using Windows Headers

mitrmkar 1,056 Posting Virtuoso

I saw the functionn GetConsoleWindow() in MSDN but I am unable to use it in both the compilers I have ( Dev C++ & Code::Blocks ) Please Help

You need to ... #define _WIN32_WINNT 0x0500 // ... or higher

mitrmkar 1,056 Posting Virtuoso

Here you go.

You are trying to define the application's resources in the .cpp file. That cannot be done. Instead,

  • save the Gui.cpp as e.g.
  • resource.rc
  • (= resource script)
  • add the
  • resource.rc
  • file to your project
  • then you might copy/paste the following code into Gui.cpp (it's pretty much standard Dev-C++ Win Gui application code). Assuming that you have created a Win32 GUI project.
  • then compile and run
#include <windows.h>
#include "resource.h" // <- needed for the menu ID (IDR_MYMENU)

/*  Declare Windows procedure  */
LRESULT CALLBACK WindowProcedure (HWND, UINT, WPARAM, LPARAM);

/*  Make the class name into a global variable  */
char szClassName[ ] = "WindowsApp";

int WINAPI WinMain (HINSTANCE hThisInstance,
                    HINSTANCE hPrevInstance,
                    LPSTR lpszArgument,
                    int nFunsterStil)

{
    HWND hwnd;               /* This is the handle for our window */
    MSG messages;            /* Here messages to the application are saved */
    WNDCLASSEX wincl;        /* Data structure for the windowclass */

    /* The Window structure */
    wincl.hInstance = hThisInstance;
    wincl.lpszClassName = szClassName;
    wincl.lpfnWndProc = WindowProcedure;      /* This function is called by windows */
    wincl.style = CS_DBLCLKS;                 /* Catch double-clicks */
    wincl.cbSize = sizeof (WNDCLASSEX);

    /* Use default icon and mouse-pointer */
    wincl.hIcon = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
    wincl.hCursor = LoadCursor (NULL, IDC_ARROW);
    wincl.lpszMenuName = NULL;                 /* No menu */
    wincl.cbClsExtra = 0;                      /* No extra bytes after the window class */
    wincl.cbWndExtra = 0;                      /* structure or the window instance */
    /* Use Windows's default color as the background of the window …
mitrmkar 1,056 Posting Virtuoso

Could you post the Gui.cpp file?

mitrmkar 1,056 Posting Virtuoso

Is there a command that hides the dos window while the program executes??

You might be looking for something like this
http://www.codeproject.com/KB/winsdk/runsilent.aspx

mitrmkar 1,056 Posting Virtuoso

It worked. I red about it so something like this:

´When this property is set to false, selected nodes in the TreeView control remain highlighted in a different color than the current selection color when the TreeView control loses focus.´

Just a note, you've been reading the TreeView control documentation. In general, try to be as accurate as you can i.e. reading the RichTextBox documentation in this case.

mitrmkar 1,056 Posting Virtuoso

You might want to set the HideSelection property of the RichTextBox to false.

mitrmkar 1,056 Posting Virtuoso

I compiled it and ran it as an exe file :(

sorry this is not my area,

Say your .html file's full path is: "d:\folder\file.html", then the following command should do

// open the .html in default browser
system("start file://d:/folder/file.html");