can any one suggest me solution please

//CAtlString str=(_T(buffer)); //buffer wil have{{ ( ab != cd } == true }} as my input
CString str=(_T(buffer));
CString symb[10]={ "{{","}}","==","<=",">=","!=" , "true", "flase", '(', ')' };
(LPCTSTR)str.trim(_T(symb));

if i am trying to execute this code iam getting some errors like

1>d:\c++_test_code\simple\simple\simpledlg.cpp(197) : error C2065: 'Lbuffer' : undeclared identifier
1>d:\c++_test_code\simple\simple\simpledlg.cpp(198) : error C2440: 'initializing' : cannot convert from 'const char [3]' to 'CString'
1> Constructor for class 'ATL::CStringT<BaseType,StringTraits>' is declared 'explicit'
1> with
1> [
1> BaseType=wchar_t,
1> StringTraits=StrTraitMFC_DLL<wchar_t>
1> ]
1>d:\c++_test_code\simple\simple\simpledlg.cpp(198) : error C2440: 'initializing' : cannot convert from 'const char [3]' to 'CString'
1> Constructor for class 'ATL::CStringT<BaseType,StringTraits>' is declared 'explicit'
1> with
1> [
1> BaseType=wchar_t,
1> StringTraits=StrTraitMFC_DLL<wchar_t>
1> ]
1>d:\c++_test_code\simple\simple\simpledlg.cpp(198) : error C2440: 'initializing' : cannot convert from 'const char [3]' to 'CString'
1> Constructor for class 'ATL::CStringT<BaseType,StringTraits>' is declared 'explicit'
1> with
1> [
1> BaseType=wchar_t,
1> StringTraits=StrTraitMFC_DLL<wchar_t>
1> ]
1>d:\c++_test_code\simple\simple\simpledlg.cpp(198) : error C2440: 'initializing' : cannot convert from 'const char [3]' to 'CString'
1> Constructor for class 'ATL::CStringT<BaseType,StringTraits>' is declared 'explicit'
1> with
1> [
1> BaseType=wchar_t,
1> StringTraits=StrTraitMFC_DLL<wchar_t>
1> ]
1>d:\c++_test_code\simple\simple\simpledlg.cpp(198) : error C2440: 'initializing' : cannot convert from 'const char [3]' to 'CString'
1> Constructor for class 'ATL::CStringT<BaseType,StringTraits>' is declared 'explicit'
1> with
1> [
1> BaseType=wchar_t,
1> StringTraits=StrTraitMFC_DLL<wchar_t>
1> ]
1>d:\c++_test_code\simple\simple\simpledlg.cpp(198) : error C2440: 'initializing' : cannot convert from 'const char [3]' to 'CString'
1> Constructor for class 'ATL::CStringT<BaseType,StringTraits>' is declared 'explicit'
1> with
1> [
1> BaseType=wchar_t,
1> StringTraits=StrTraitMFC_DLL<wchar_t>
1> ]
1>d:\c++_test_code\simple\simple\simpledlg.cpp(198) : error C2440: 'initializing' : cannot convert from 'const char [5]' to 'CString'
1> Constructor for class 'ATL::CStringT<BaseType,StringTraits>' is declared 'explicit'
1> with
1> [
1> BaseType=wchar_t,
1> StringTraits=StrTraitMFC_DLL<wchar_t>
1> ]
1>d:\c++_test_code\simple\simple\simpledlg.cpp(198) : error C2440: 'initializing' : cannot convert from 'const char [6]' to 'CString'
1> Constructor for class 'ATL::CStringT<BaseType,StringTraits>' is declared 'explicit'
1> with
1> [
1> BaseType=wchar_t,
1> StringTraits=StrTraitMFC_DLL<wchar_t>
1> ]
1>d:\c++_test_code\simple\simple\simpledlg.cpp(198) : error C2440: 'initializing' : cannot convert from 'char' to 'CString'
1> Constructor for class 'ATL::CStringT<BaseType,StringTraits>' is declared 'explicit'
1> with
1> [
1> BaseType=wchar_t,
1> StringTraits=StrTraitMFC_DLL<wchar_t>
1> ]
1>d:\c++_test_code\simple\simple\simpledlg.cpp(198) : error C2440: 'initializing' : cannot convert from 'char' to 'CString'
1> Constructor for class 'ATL::CStringT<BaseType,StringTraits>' is declared 'explicit'
1> with
1> [
1> BaseType=wchar_t,
1> StringTraits=StrTraitMFC_DLL<wchar_t>
1> ]
1>d:\c++_test_code\simple\simple\simpledlg.cpp(199) : error C2039: 'trim' : is not a member of 'ATL::CStringT<BaseType,StringTraits>'
1> with
1> [
1> BaseType=wchar_t,
1> StringTraits=StrTraitMFC_DLL<wchar_t>
1> ]
1>d:\c++_test_code\simple\simple\simpledlg.cpp(199) : error C2065: 'Lsymb' : undeclared identifier

Edited 6 Years Ago by Nick Evan: added code-tags

>>CString str=(_T(buffer));

The _T macro only works with string literals, not character arrays. For example _T("Hello") If you want to convert a character array from char* to wchar_t* you have to use one of the convertion functions. Here is a thread that will show you how to do that.

The problem on line 3 of the code you posted is that you failed to use _T macro around those string literals.

Edited 6 Years Ago by Ancient Dragon: n/a

Thank you EVAN thank you very much but,

Actually i am not an expert in c++ but i was asked to develop tool in vc++ with the above requirement(which changes accordingly). can u elobarate your solution...

as i already gave my input
//CAtlString str=(_T(buffer));
//buffer wil have{{ ( ab != cd } == true }} as my input(for example) and i jus want only ab in one line and cd in another line as my output
CString str=(_T(buffer));
CString symb[10]={ "{{","}}","==","<=",">=","!=" , "true", "flase", '(', ')' };
(LPCTSTR)str.trim(_T(symb));

Compile and run that example program that is given in the link that I posted -- it says it all. What you are trying to do is convert from char* to wchar_t* which is used for UNICODE (different languages such as English, Spanish, German, Russian, Japanese, Chinese, etc). CString class will not make the conversion for you, so you have to convert the buffer yourself before assigning it to a CString object. Pay particular attention to that mbstowcs_s() call.

Edited 6 Years Ago by Ancient Dragon: n/a

thank you once again....

char *ar=buffer;
fprintf(fp2,ar);
str = ar;
CString symb[]={"{{"};
this piece of code should work right.

but i am getting error like
1>d:\c++_test_code\simple\simple\simpledlg.cpp(201) : error C2440: 'initializing' : cannot convert from 'const char [3]' to 'CString'
1> Constructor for class 'ATL::CStringT<BaseType,StringTraits>' is declared 'explicit'
1> with
1> [
1> BaseType=wchar_t,
1> StringTraits=StrTraitMFC_DLL<wchar_t>
1> ]

whats the mistake i am doing... plz dont feel bad and suggest me a solution....

I've already told you that you have to surround string literals with the _T macro CString symb[]= {_T("{{")}; . The reason you have to do that is because you are compiling your program for UNICODE, so all strings both literals and non-literals must be UNICODE.

Edited 6 Years Ago by Ancient Dragon: n/a

the reason why i am taking the symb is to remove all the symbols in buffer.

so i used trim function. like this

char *ar=buffer;
CString cs(ar);
CString symb[]= {_T("{{" , "}}" ,"true" , "false")};
cs.Trim(symb); //can i use trim like this

if i use i am getting error like
1>d:\c++_test_code\simple\simple\simpledlg.cpp(206) : error C2664: 'ATL::CStringT<BaseType,StringTraits> &ATL::CStringT<BaseType,StringTraits>::Trim(wchar_t)' : cannot convert parameter 1 from 'CString [1]' to 'wchar_t'
1> with
1> [
1> BaseType=wchar_t,
1> StringTraits=StrTraitMFC_DLL<wchar_t>
1> ]
1> There is no context in which this conversion is possible


Thank You for helping me so much...

cs.Trim(LPCTSTR(symb)); //trimming is not happening even if i use this

You are using Trim() incorrectly. None of the Trim overloads take a CString parameter. Nor should the parameter be an array of strings -- only one string that contains the characters you want it to use for trimming. See this example for how to use Trim() correctly.

Edited 6 Years Ago by Ancient Dragon: n/a

thanks for the example and
is there any function if i want to trim an array of charecters from a cstring...??

thanks for the example you have given
and
is there any function which can trim an array of selected charecters from a string....???

This article has been dead for over six months. Start a new discussion instead.