Advertisement

char to char *

Started by July 19, 2000 03:46 PM
22 comments, last by KalvinB 24 years, 5 months ago
lemme try:
        #include <iostream.h>void main(){cout << "cool!" << endl;}        


a2k

Edited by - a2k on July 21, 2000 1:10:00 PM
------------------General Equation, this is Private Function reporting for duty, sir!a2k
Vlion:


The standard string class (defined in ''string'', ''string.h'' is the C string functions) lives in the std namespace. You can write ''std::string'' when you want a string, or add ''using std::string'' at the top of the file and just use ''string'' without the std:: when you need it.
Advertisement
It seems to me that a CString will solve all your problems. It is variable length, and you can use "normal" operators on it. If you are using MSCV++ just look up CString in the help and under one of the related links it tells you what file to include.

    CString myStr;myStr += "Hello";myStr += '' ''; // I am not quite sure this will work... I think it willmyStr += "World";    

After that code, myStr would hold "Hello World", and you never had to do anything related to telling it how much memory you need

--------------------


You are not a real programmer until you end all your sentences with semicolons;

Yanroy@usa.com

Visit the ROAD Programming Website for more programming help.

--------------------

You are not a real programmer until you end all your sentences with semicolons; (c) 2000 ROAD Programming
You are unique. Just like everybody else.
"Mechanical engineers design weapons; civil engineers design targets."
"Sensitivity is adjustable, so you can set it to detect elephants and other small creatures." -- Product Description for a vibration sensor

Yanroy@usa.com

I tried the CString but afx.h is giving me linking errors.

std::string for some reason is failing to get the message across in DirectPlay.

    (CLIENT)struct GAMEMSG_GENERIC{    DWORD dwType;    std::string message;	};GAMEMSG_GENERIC msgWave;msgWave.message.erase();msgWave.message += "hello you server you.";msgWave.dwType = 1;g_pDP->Send( g_LocalPlayerDPID, 1, 0, &msgWave, sizeof msgWave) );(SERVER)HRESULT HandleAppMessages( HWND hDlg, GAMEMSG_GENERIC* pMsg, DWORD dwMsgSize,                            DPID idFrom, DPID idTo ){LogFile<<"Type:"<<pMsg->dwType<<" Size:"<<dwMsgSize<<" From:"<<idFrom<<" To:"<<idTo<<"\n";LogFile<<pMsg->message.c_str()<<"\n";    


The server''s log file correctly shows the type, size, from and to but the message is empty.

I''m assumming I have to convert the message to a char * and send that accross and then convert back to read it.

DirectPlay has no problem getting char* sent.

Ben

This topic is closed to new replies.

Advertisement