Home > Back-end >  VS character set compiling a success
VS character set compiling a success

Time:12-31

I use the open source library muParser, is used for parsing formula
The sample code:
 
#include
# include "muParser. H"


Int main (int arg c, char * argv [])
{

Double var_a=1;
Mu: : Parser p;
P. etExpr (" 3 * 8 + 9-1/8 ");
STD: : cout & lt; return 0;
}

Use VS2019, project character set must be set to "use multi-byte character set", to compile successfully,

If you use the default "Unicode character set, the IDE will detect the error types:

E0415 does not exist from "const char [10]" into "STD: : basic_string & lt; Would be, STD: : char_traits & lt; Would be & gt; , STD: : allocatorC2664 "void mu: : ParserBase: : SetExpr (const mu: : string_type & amp;) 1 cannot be the parameter ": from" const char [10] "into" const mu: : string_type & amp;" ConsoleApplication1


I will, "" string substitution into _T (" "), the IDE type error will disappear, but the compilation times wrong:

error LNK2019 cannot resolve the external symbol "__declspec (dllimport) public: void __cdecl mu: : ParserBase: : SetExpr (class STD: : basic_string & lt; Unsigned short, struct STD: : char_traits & lt; Unsigned short> Class, STD: : allocator Const & amp;) "(__imp_? SetExpr @ ParserBase @ mu @ @ QEAAXAEBV? $basic_string @ GU? $char_traits @ G @ STD @ @ V? $allocator @ G @ @ @ STD @ @ @ 2 Z), the main function of cites the symbol ConsoleApplication1

Unable to connect to dynamic library seems to be

Excuse me, if I must use the Unicode character set, can solve this problem?

CodePudding user response:

Fyi:
 # pragma warning (4786) disable: 
#include
#include
#include
using namespace std;
Int main () {
Wstring ws1, ws2;

Wcin. Imbue (locale (" CHS "));
Wcout. Imbue (locale (" CHS "));
Getline (wcin, ws1);
Getline (wcin, ws2);
If (ws1. The size ()!=ws2. The size ()) {
Wcoutreturn 1;
}

MapInt n=ws1. The size ();

for (int i=0; iIf (m1), find (ws1 [I])==m1. The end () & amp; & M2. The find (ws2 [I])==m2. The end ()) {
M1 [ws1 [I]]=ws2 [I];
M2 [ws2 [I]]=ws1 [I];
} else {
If (m1 [ws1 [I]].=ws2 [I] | | m2 [ws2 [I]].=ws1 [I]) {
Wcoutreturn 1;
}
}
}
Wcoutreturn 0;
}

CodePudding user response:

IDE string coding is used, A wide character W, IDE don't know, need to use _T, turn CA2W etc.
That you are using dynamic repository is Assic single character set, so add _T after multiple character sets, the IDE met, don't know dynamic library
If the library is Assic, and must use Unicode code, writing the code with _T or CA2W turn, turn again odd character set CW2A call library

CodePudding user response:

refer to the second floor Chgooo response:
IDE string encoding is A,, when using wide character W IDE don't know, need to use _T, turn CA2W etc.
That you are using dynamic repository is Assic single character set, so add _T after multiple character sets, the IDE met, don't know dynamic library
If the library is Assic, and must use Unicode code, writing the code with _T or CA2W turn, turn again call library where the odd character set CW2A

Specific what to do?

CodePudding user response:

reference administrator reply: 3/f
Quote: refer to the second floor Chgooo response:
IDE string encoding is A,, when using wide character W IDE don't know, need to use _T, turn CA2W etc.
That you are using dynamic repository is Assic single character set, so add _T after multiple character sets, the IDE met, don't know dynamic library
If the library is Assic, and must use Unicode code, writing the code with _T or CA2W turn, turn again call library where the odd character set CW2A

Specific what to do?


First single character set, the above answer some more character set wrong, should not affect understanding

Two solutions
1, the project must use the Unicode character set
All strings in code or _T CA2W conversion, this IDE no longer error
Call library functions, string constants can be directly introduced into, char * string and other variables can also directly come to join
Through _T or CA2W convert a string to use CW2A odd character set to preach and
More than 2, the project can use character set, directly set for character set, don't need to turn

Anyway, a word CW2A, CA2W to turn, no error is right


  • Related