静态库API问题(std :: string与char *) [英] Static library API question (std::string vs. char*)
问题描述
我以前没有使用过静态库,但是现在我需要.
I have not worked with static libraries before, but now I need to.
我正在Unix中编写一个控制台应用程序.我很容易在任何地方使用std::string
,因为这样做很容易.但是,我最近发现我必须在Windows中支持它,并且第三方应用程序的代码中需要使用API(我将不会共享源代码,而只会共享DLL).
I am writing a console app in Unix. I freely use std::string
everywhere because it's easy to do so. However, I recently found out that I have to support it in Windows and a third party application would need API's to my code (I will not be sharing source, just the DLL).
考虑到这一点,我仍然可以在代码中的任何地方使用std::string
,但是在编写API时为它们提供char *
吗?那行得通吗?
With this in mind, can I still use std::string
everywhere in my code but then provide them with char *
when I code the API's? Would that work?
推荐答案
是的.在内部使用std::string
,然后在接口函数上使用const char *
(输入时将转换为std::string
.
Yep. Use std::string
internally and then just use const char *
on the interface functions (which will be converted to std::string
s on input.
这篇关于静态库API问题(std :: string与char *)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!