VC .NETÖÐString^ ÓëANSI C char*»¥×ª
VC.NETÖеÄStringÀàÊÇÀûÓÃUnicode×Ö·û¼¯±àÂëÀ´±íʾÎı¾¡£Unicode×Ö·û¼¯ÖÐÿ¸ö×Ö·û(ºº×Ö¡¢Ó¢ÎÄ×Öĸ)¶¼Õ¼2¸ö×Ö½Ú£¬ÇÒÆä×Ö·û´®ÊÇÒÔ2¸öÁ¬ÐøµÄ\0½áβµÄ¡£
ANSIµÄASCII×Ö·û¼¯ÊÇ×î³£¼ûµÄ×Ö·û¼¯£¬³£ÓÃÓÚ±íʾtxtµÄÎı¾Îļþ¡£ÔÚASCII×Ö·û¼¯ÖÐÓ¢ÎÄÕ¼Ò»¸ö×Ö½Ú£¬ºº×Ö2¸ö×Ö½Ú£¬ÇÒÆä×Ö·û´®ÊÇÒÔÒ»¸ö\0½áβµÄ¡£
ÔÚÀûÓÃVC.NET½øÐлìºÏ±à³Ìʱ£¬¾³£ÐèҪʵÏÖStringÓëchar*µÄ»¥×ª£¬ÀýÈçÔÚTextBox¿Ø¼þÖÐÊäÈëµÄText×÷Ϊfopen»òÕßCreateFileµÄÎļþÃû²ÎÊýʱ£¬³£ÐèҪʵÏÖchar*µÄת»¯¡£¹ÊÌṩÈçϵÄת»¯·½·¨£º
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
int main(array<System::String ^> ^args)
{
// String^ converts to char*
char szDestOutChar[256];
String^ SrcInStr = "C:\\Documents and Settings\\Adiminstrator\\ÎÒµÄÎĵµ\\swq.txt";
int SourceStrLen = SrcInStr->Length;
wchar_t *pwszStr = new wchar_t[SourceStrLen + 1];
array <System::Char>^ pClr = SrcInStr->ToCharArray();
for (int i = 0; i < SourceStrLen; i++)
{
pwszStr[i] = pClr[i];
}
pwszStr[SourceStrLen] = '\0';
::WideCharToMultiByte(CP_ACP, NULL, pwszStr, -1, szDestOutChar, 256, NULL, NULL);
// char* converts to String^
char* szInSrcChar = "C:\\Documents and Settings\\Adiminstrator\\ÎÒµÄÎĵµ\\swq.txt";
int wcsLen = ::MultiByteToWideChar(CP_ACP, NULL, szInSrcChar, strlen(szInSrcChar), NULL, 0);
wchar_t* wszStr = new wchar_t[wcsLen + 1];
::MultiByteToWideChar(CP_ACP, NULL, szInSrcChar, strlen(szInSrcChar), wszStr, wcsLen);
wszStr[wcsLen] = '\0';
String^ ClrOutStr = gcnew String(wszStr);
System::Console::WriteLine("Press ENTER key to exit !");
System::Console::Read();
delete pwszStr;
delete wszStr;
return 0;
}
Ïà¹ØÎĵµ£º
Á´±í¶¨Òå¼°²Ù×÷µÄÔ´Îļþ£ºemployee.h
//
#pragma once
#ifndef __EMPLOYEE_H__
#define __EMPLOYEE_H__
#include<stdio.h>
#include<malloc.h>
typedef struct employee{
int id;
int age;
int salary;
}EmpType;
typedef struct Node{
EmpType data;
struct Node *next;
}L ......
Ò» £º½â¾öC»òC++ÖеÄmultiple definition ofÎÊÌâ
server.cpp
clientp2p.cpp
#include "exception.h"
#include "clientp2p.h"
clientp2p.h
ÖÐдÓÐËùÓеÄÈ«¾Ö±äÁ¿¼°Æä³õʼ»¯Öµ
ºÍº¯ÊýÉùÃ÷
1.server.cppÖУº
ÒýÓÃ
£º
#include "clientp2p.h"
int Main(....)
{
...
}
2.clientp ......
Ò»¸ö¶¨ÒåΪvolatileµÄ±äÁ¿ÊÇ˵Õâ±äÁ¿¿ÉÄܻᱻÒâÏë²»µ½µØ¸Ä±ä£¬ÕâÑù£¬±àÒëÆ÷¾Í²»»áÈ¥¼ÙÉèÕâ¸ö±äÁ¿µÄÖµÁË¡£¾«È·µØ˵¾ÍÊÇ£¬ÓÅ»¯Æ÷ÔÚÓõ½Õâ¸ö±äÁ¿Ê±±ØÐëÿ´Î¶¼Ð¡ÐĵØÖØжÁÈ¡Õâ¸ö±äÁ¿µÄÖµ£¬¶ø²»ÊÇʹÓñ£´æÔڼĴæÆ÷ÀïµÄ±¸·Ý¡£ÏÂÃæÊÇvolatile±äÁ¿µÄ¼¸¸öÀý×Ó£º
1). ²¢ÐÐÉ豸µÄÓ²¼þ¼Ä´æÆ÷£¨È磺״̬¼Ä´æÆ ......
ʱ³£ÔÚcppµÄ´úÂëÖ®Öп´µ½ÕâÑùµÄ´úÂë:
#ifdef __cplusplus
extern "C" {
#endif
//Ò»¶Î´úÂë
#ifdef __cplusplus
}
#endif
¡¡¡¡ÕâÑùµÄ´úÂëµ½µ×ÊÇʲôÒâ˼ÄØ£¿Ê×ÏÈ£¬__cplusplusÊÇcppÖеÄ×Ô¶¨Òåºê£¬ÄÇô¶¨ÒåÁËÕâ¸öºêµÄ»°±íʾÕâÊÇÒ ......
Ç°ÑÔ
Eclipse×÷Ϊһ¿î¼«ÆäÓÅÐãµÄJava IDE£¬ÒѾµÃµ½¹ã·ºµÄÈÏ¿É¡£µ±È»Eclipse²¢²»ÏÞÓÚJava¿ª·¢£¬ÓÉÓÚÆäÓÅÐãµÄ»ù´¡¼Ü¹¹£¬EclipseÒѾ³ÉΪһ¸ö¿ÉÒÔÈÝÄÉÒ»ÇÐÓ뿪·¢ÓйصŤ¾ßµÄƽ̨¡£
µ±È»ÈÝÄÉÒ»Çв¢²»Òâζ×ÅÊʺÏÓÚÒ»ÇС£ÏñC/C++ÕâÑùÔç¾Í´æÔڵIJ¢¹ã·ºÓ¦ÓõÄÓïÑÔ£¬Ôç¾ÍÓÐÒ»´óÅú¿ÉÓõÄIDE£¬Ò²ÓкܶàÈËϲ»¶ÓÃvi/emacs×÷Ϊ×Ô¼ºµÄ¿ ......