basic_string problem 
Author Message
 basic_string problem

Hi

I am having a strange problem with basic_string. If  i call a method in
another DLL passing basic_string reference, when i try to concat the two
basic_string it didn't.
if str has the value 'VALUE'
foo::foo(MyDatabase* db, const basic_string& str)
{
...
...
m_localbasic_string  = _T("do something with");  ---1
m_localbasic_string+=  str;                                 ---2
m_localbasic_string+= _T(" and run store proc");---3
...
...
..

Quote:
}

if i check the value of m_localbasic_string after step 2 i only see 'do
somehting with' it didn't concat the string??? why?

regards,
HCX



Sat, 11 Oct 2003 19:51:28 GMT  
 basic_string problem
what is the templatized type you are using for basic_string?  ie:
basic_sting<char>
I was able to do the following in c:

#pragma warning(disable:4786)

#include "stdafx.h"
#include <string>
#include "TCHAR.H"

using namespace std;

ffoo(const basic_string<char>& str);

int main(int argc, char* argv[])
{
 basic_string<char> ast = _T("my sting");

 ffoo(ast);
 ast += " more stuff in the string";
 return 0;

Quote:
}

ffoo(const basic_string<char>& str)
{

 basic_string<char> m_localbasic_string;

m_localbasic_string  = _T("do something with");  //---1
m_localbasic_string+=  str;                        //         ---2
m_localbasic_string+= _T(" and run store proc");//---3

Quote:
}

Steven Szelei


Quote:
> Hi

> I am having a strange problem with basic_string. If  i call a method in
> another DLL passing basic_string reference, when i try to concat the two
> basic_string it didn't.
> if str has the value 'VALUE'
> foo::foo(MyDatabase* db, const basic_string& str)
> {
> ...
> ...
> m_localbasic_string  = _T("do something with");  ---1
> m_localbasic_string+=  str;                                 ---2
> m_localbasic_string+= _T(" and run store proc");---3
> ...
> ...
> ..
> }

> if i check the value of m_localbasic_string after step 2 i only see 'do
> somehting with' it didn't concat the string??? why?

> regards,
> HCX



Sat, 11 Oct 2003 22:56:21 GMT  
 basic_string problem
im using the template basic_string<wchar_t, char_traits<wchar_t>,
 allocator<wchar_t> > that is same as wstring. but not working?


Quote:
> what is the templatized type you are using for basic_string?  ie:
> basic_sting<char>
> I was able to do the following in c:

> #pragma warning(disable:4786)

> #include "stdafx.h"
> #include <string>
> #include "TCHAR.H"

> using namespace std;

> ffoo(const basic_string<char>& str);

> int main(int argc, char* argv[])
> {
>  basic_string<char> ast = _T("my sting");

>  ffoo(ast);
>  ast += " more stuff in the string";
>  return 0;
> }

> ffoo(const basic_string<char>& str)
> {

>  basic_string<char> m_localbasic_string;

> m_localbasic_string  = _T("do something with");  file://---1
> m_localbasic_string+=  str;                        //         ---2
> m_localbasic_string+= _T(" and run store proc");//---3

> }

> Steven Szelei



> > Hi

> > I am having a strange problem with basic_string. If  i call a method in
> > another DLL passing basic_string reference, when i try to concat the two
> > basic_string it didn't.
> > if str has the value 'VALUE'
> > foo::foo(MyDatabase* db, const basic_string& str)
> > {
> > ...
> > ...
> > m_localbasic_string  = _T("do something with");  ---1
> > m_localbasic_string+=  str;                                 ---2
> > m_localbasic_string+= _T(" and run store proc");---3
> > ...
> > ...
> > ..
> > }

> > if i check the value of m_localbasic_string after step 2 i only see 'do
> > somehting with' it didn't concat the string??? why?

> > regards,
> > HCX



Sat, 11 Oct 2003 23:24:22 GMT  
 basic_string problem
you should be using L"some string" rather than _T("my string")
here is the fix using wchar_t.

#pragma warning(disable:4786)

#include "stdafx.h"
#include <xstring>
#include "TCHAR.H"
#include <iostream>

using namespace std;

typedef basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t> >
mybasestr;

ffoo(const mybasestr &str);

int main(int argc, char* argv[])
{

 mybasestr ast = _L("my sting");
 wcout << "str = " << ast.c_str() << endl;
 ffoo(ast);
 ast += _L(" more stuff in the string");
 wcout << "str = " << ast.c_str() << endl;

 return 0;

Quote:
}

ffoo(const mybasestr& str)
{

 mybasestr m_localbasic_string;

 wcout << m_localbasic_string.c_str() << endl;
 m_localbasic_string  = _L("do something with");  //---1
 wcout << m_localbasic_string.c_str() << endl;

 m_localbasic_string+=  str;                        //         ---2
 wcout << m_localbasic_string.c_str() << endl;

 m_localbasic_string+= _L(" and run store proc");//---3
 wcout << m_localbasic_string.c_str() << endl;

Quote:
}

Steven Szelei.


Quote:
> im using the template basic_string<wchar_t, char_traits<wchar_t>,
>  allocator<wchar_t> > that is same as wstring. but not working?



> > what is the templatized type you are using for basic_string?  ie:
> > basic_sting<char>
> > I was able to do the following in c:

> > #pragma warning(disable:4786)

> > #include "stdafx.h"
> > #include <string>
> > #include "TCHAR.H"

> > using namespace std;

> > ffoo(const basic_string<char>& str);

> > int main(int argc, char* argv[])
> > {
> >  basic_string<char> ast = _T("my sting");

> >  ffoo(ast);
> >  ast += " more stuff in the string";
> >  return 0;
> > }

> > ffoo(const basic_string<char>& str)
> > {

> >  basic_string<char> m_localbasic_string;

> > m_localbasic_string  = _T("do something with");  file://---1
> > m_localbasic_string+=  str;                        //         ---2
> > m_localbasic_string+= _T(" and run store proc");//---3

> > }

> > Steven Szelei



> > > Hi

> > > I am having a strange problem with basic_string. If  i call a method
in
> > > another DLL passing basic_string reference, when i try to concat the
two
> > > basic_string it didn't.
> > > if str has the value 'VALUE'
> > > foo::foo(MyDatabase* db, const basic_string& str)
> > > {
> > > ...
> > > ...
> > > m_localbasic_string  = _T("do something with");  ---1
> > > m_localbasic_string+=  str;                                 ---2
> > > m_localbasic_string+= _T(" and run store proc");---3
> > > ...
> > > ...
> > > ..
> > > }

> > > if i check the value of m_localbasic_string after step 2 i only see
'do
> > > somehting with' it didn't concat the string??? why?

> > > regards,
> > > HCX



Sun, 12 Oct 2003 01:26:49 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. basic_string<>::data() vs basic_string<>::c_str()

2. assigning basic_string to basic_string - is this by design?

3. problem with std::basic_string's copy constructor

4. Problems with basic_string.insert(iterator, _E)

5. Thread safety problem with (patched) basic_string.

6. Missed conversion operator in basic_string

7. BUG: autoexp.dat is wrong for std:basic_string

8. Using basic_string in C#

9. basic_string case insencitive search

10. Case insensitive compare in STL basic_string

11. BUG: autoexp.dat is wrong for std:basic_string

12. basic_string

 

 
Powered by phpBB® Forum Software