Re: Problem with using char* to return string by reference
swtbase@gmail.com <swtbase@gmail.com> wrote:
On Jun 13, 5:35 pm, Hendrik Schober <Spamt...@gmx.de> wrote:
Giovanni Dicanio schrieb:
"Hendrik Schober" <Spamt...@gmx.de> ha scritto nel messaggio
news:%232rgTrTzIHA.3884@TK2MSFTNGP05.phx.gbl...
(I've never used them.)
Well, in these modern days I think that it makes sense to just use Unicode,
and forget about ANSI.
(Considering that new Windows Vista APIs are Unicode-only, too...)
So, if one likes STL strings, I think that directly using std::wstring,
wchar_t*, etc. (and not TCHAR stuff) in code is just fine.
I've created a similar setup (typedef'd char type, and based
on that 'std::basic_string<>' instances) a couple of years
age, that's been used in many projects. But since these are
ported across many platforms, Windows API stuff wasn't used.
Is std::string usable in non-MFC apps?
Since the 'std' indicates it's part of the C++ standard
library, you can expect it to work on any std-conforming
compiler.
Is std::string able to handle UNICODE strings?
No.
But 'std::string' is just a 'typedef'd name for
std::basic_string<char>
and there is also 'std::wstring', which is a synonym for
std::basic_string<wchar_t>
Using VC, 'wchar_t' is 16bit and thus able to store the
UCS-2 characters Windows uses for Unicode.
Is my program safer from buffer-overrun problems if I pass
'std::string's object as reference in functions?
I don't know which functions you're talking about and I
don't know what the alternative would be (passing them by
value?), so I'm not sure how to answer this.
Generally, buffer overruns happen when you try to put too
much data into to too little a buffer. To prevent this,
you'll either have to manually check the data's size or
you'll have to use ways to input your data that grow the
buffer automatically:
std::string field;
std::getline(input_stream,field'\t');
The latter is, of course, safer.
I used the following statement in my console app:
include <string>
using namespace std;
int main()
{
string a = L"This is a test string.";
/* Here when I type 'a.' the Intellisense should have given me
the methods available for a. But it doesn't why?*/
return 0;
}
My usage may be wrong in the above code. Please correct me. I want to
have all the basic string manipulation functionality like in VB6 but
also don't want to lose UNICODE support.
So use 'std::wstring':
#include <string>
#include <iostream>
int main()
{
std::wstring u = L"wide string test";
std::wcout << u << L'\n';
return 0;
}
Intellisense is notoriously unreliable for C++. If you
want better results, buy Visual Assist.
Schobi
--
SpamTrap@gmx.de is never read
I'm HSchober at gmx dot de
"I guess at some point idealism meets human nature and
explodes." Daniel Orner