2010-01-16 50 views

回答

9

如果您對使用C字符串感到滿意,您可能會對my answer感興趣。


沒有必要編譯代碼爲C++:編譯entities.c-std=c99和目標文件與你的C++代碼,例如鏈接,如果您在follwing示例程序foo.cpp

#include <iostream> 

extern "C" size_t decode_html_entities_utf8(char *dest, const char *src); 

int main() 
{ 
    char line[100]; 
    std::cout << "Enter encoded line: "; 
    std::cin.getline(line, sizeof line); 
    decode_html_entities_utf8(line, 0); 
    std::cout << line; 
    return 0; 
} 

使用

g++ -o foo foo.cpp entities.o 
+0

我使用此代碼來使用它: #include「entities.h」 的#include INT主(無效) { \t的printf( 「輸入編碼的文本:」); \t char *編碼,*解碼; \t scanf(「%s」,編碼); \t size_t tmp = decode_html_entities_utf8(解碼,編碼); \t printf(「%s \ n」,解碼); \t return 0; } 保存爲entdec.c 然後我跑: GCC -c entities.c entdec.c -std = C99 的gcc -o entdec entities.o entdec.o 我打開該程序,我得到這個: 輸入編碼的文本:"音樂" & "視頻" 和strage字符。 – Eduardo 2010-01-16 19:41:21

+0

@Eduardo:scanf()'不是我的解碼函數會爲你分配內存;我將添加一些示例代碼 – Christoph 2010-01-16 19:47:08

+0

謝謝,現在它工作。 – Eduardo 2010-01-16 20:06:09