0
 string utf2oem( string const & in_str ) { int n = MultiByteToWideChar( CP_UTF8, 0, in_str.data(), in_str.size(), NULL, 0 ); if( n == 0 ) return in_str; wstring tmp; tmp.resize( n ); int ret = MultiByteToWideChar(CP_UTF8, 0, in_str.data(), in_str.size(), &tmp.front(), tmp.size() ); if( ret == 0 ) return in_str; string out_str; out_str.resize( n ); ret = WideCharToMultiByte(CP_OEMCP, 0, tmp.data(), n, &out_str.front(), n, NULL, NULL); return( ret == 0 ? in_str : out_str ); } 

I try to use this function but get error : error C2039: 'front' : is not a member of 'std::basic_string<_Elem,_Traits,_Ax>'

So can i use something instead front() in Visual C++ 2008 with boost 1.38?

1

1 Answer 1

2

Front returns first element, so you can manually refer to it. You can acces to element like in a table.

&our_str[0] //insted of &our_str.front() 

Or use the function .data() made specifically to this. But remember "Modifying the character array accessed through data is undefined behavior." (from en.cppreference.com)

our_str.data() 

But if you need an iterator to begin, you can use .begin().

our_str.begin() 

More about strings you can read here.

Sign up to request clarification or add additional context in comments.

1 Comment

Note that mutating the buffer behind data() is not defined to have correct behavior :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.