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;
}
Ïà¹ØÎĵµ£º
1.Ö¸ÕëºÍÒýÓÃÓÐʲô·Ö±ð£»Èç¹û´«ÒýÓñȴ«Ö¸Õ밲ȫ£¬ÎªÊ²Ã´£¿Èç¹ûÎÒʹÓó£Á¿Ö¸ÕëÄѵÀ²»ÐÐÂð£¿
(1) ÒýÓÃÔÚ´´½¨µÄͬʱ±ØÐë³õʼ»¯£¬¼´ÒýÓõ½Ò»¸öÓÐЧµÄ¶ÔÏ󣻶øÖ¸ÕëÔÚ¶¨ÒåµÄʱºò²»±Ø³õʼ»¯£¬¿ÉÒÔÔÚ¶¨ÒåºóÃæµÄÈκεط½ÖØи³Öµ£®
(2) ²»´æÔڣΣգ̣ÌÒýÓã¬ÒýÓÃ±Ø ......
ʱ³£ÔÚcppµÄ´úÂëÖ®Öп´µ½ÕâÑùµÄ´úÂë:
#ifdef __cplusplus
extern "C" {
#endif
//Ò»¶Î´úÂë
#ifdef __cplusplus
}
#endif
¡¡¡¡ÕâÑùµÄ´úÂëµ½µ×ÊÇʲôÒâ˼ÄØ£¿Ê×ÏÈ£¬__cplusplusÊÇcppÖеÄ×Ô¶¨Òåºê£¬ÄÇô¶¨ÒåÁËÕâ¸öºêµÄ»°±íʾÕâÊÇÒ ......
C³ÌÐòÊÇÓÉÒ»×é»òÊDZäÁ¿»òÊǺ¯ÊýµÄÍⲿ¶ÔÏó×é³ÉµÄ¡£ º¯ÊýÊÇÒ»¸ö×ÔÎÒ°üº¬µÄÍê³ÉÒ»¶¨Ïà¹Ø¹¦ÄܵÄÖ´ÐдúÂë¶Î¡£ÏÂÃæС±àºÍ´ó¼Ò·ÖÏíÏÂCÓïÑÔÖеĺ¯Êý¡£
1. fgetcº¯Êý
fgetcº¯ÊýµÄ¹¦ÄÜÊÇ´ÓÁ÷ÖжÁÈ¡×Ö·û£¬ÆäÓ÷¨ÊÇ£ºint fgetc(FILE *stream); ³ÌÐòÀý×ÓÈçÏ£º
#include <string.h ......
C³ÌÐòÊÇÓÉÒ»×é»òÊDZäÁ¿»òÊǺ¯ÊýµÄÍⲿ¶ÔÏó×é³ÉµÄ¡£ º¯ÊýÊÇÒ»¸ö×ÔÎÒ°üº¬µÄÍê³ÉÒ»¶¨Ïà¹Ø¹¦ÄܵÄÖ´ÐдúÂë¶Î¡£ÏÂÃæС±àºÍ´ó¼Ò·ÖÏíÏÂCÓïÑÔÖеĺ¯Êý¡£
1. harderrº¯Êý
harderrº¯ÊýµÄ¹¦ÄÜÊǽ¨Á¢Ò»¸öÓ²¼þ´íÎó´¦Àí³ÌÐò£¬ÆäÓ÷¨ÊÇ£ºvoid harderr(int (*fptr)());³ÌÐòÀý×ÓÈçÏ£º
#include <stdio.h>
......
unzip.c
ÖÐÒýÓÃvalidate.cpp
ÎļþÖеĺ¯ÊýÀ´½øÐÐepub
¾À´í£¬²úÉúµÄÎÊÌ⣺
1.
validate.cpp
ÖÐʹÓÃiostream.h,
µ«ÊÇC
ÖÐûÓÐÕâ¸öÎļþ
£¬ËùÒÔ²úÉúµÄ´íÎó£º
2>
ÕýÔÚ±àÒë...
2>unzip.c
2>D:\Program
Files\VC\include\cstdio(25) : error C2143:
Óï·¨´íÎó:
ȱÉÙ“{ ......