PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

What am I doing wrong

As far as I can tell, eMbedded VC++ doesn't have any of the base C++ headers like <fstream>. Did I set something up wrong or are you limited to the depreciated C headers?
Kzinti · 04 Aug 2003, 23:40 UTC — What am I doing wrong
Dranith wrote:
As far as I can tell, eMbedded VC++ doesn't have any of the base C++ headers like <fstream>. Did I set something up wrong or are you limited to the depreciated C headers?


Unfortunately the C++ standard library (including the STL) doesn't come with EVC. But you can use STLport, which works perfectly.

There is nothing deprecated about the "C" headers, don't let anyone tell you otherwise.
Yeah, I looked and couldn't find any of the standard C++ library. The name, eMbedded VC++, is quite misleading. I had STLport downloaded, so I guess I'll need to figure out how to use that, thanks for the info.
Ick, I didn't know that I wouldn't beable to use iostreams, and hense std::string .. well besides that I got it all compiled and seemingly working, except that clock() doesn't seem to be defined. Did I compile something wrong? I use it for millisecond accuracy, and as far as I knew it was an ANSI function. Any suggestions?
Dranith wrote:
Ick, I didn't know that I wouldn't beable to use iostreams, and hense std::string .. well besides that I got it all compiled and seemingly working, except that clock() doesn't seem to be defined. Did I compile something wrong? I use it for millisecond accuracy, and as far as I knew it was an ANSI function. Any suggestions?


I never tried compiling the IO streams (I disabled them), but std::string does work perfectly. And so does std::wstring.
mlepage · 06 Aug 2003, 03:36 UTC — What I'm doing
I installed STLport. You can use std::string OK, just not streams.

I use the <tchar.h> routines for text. That means using _sntprintf, _tcscpy, _tfscanf, and all those wonderfully named functions.

Just be smart about it. Write a small class that encapsulates your buffer of _TCHAR and the size of that buffer. (Hint: you can use std::vector because it is array compatible, see Meyer's Effective STL book.) Make that array one more than you need, and pre-terminate it with a null character in that last position. Then always use functions that take a size: snprintf instead of sprintf, "%32s" instead of "%s" in sscanf, strncpy instead of strcpy, etc.

If you really care about performance, you can make a templated version of that class with the size as a template parameter.

This approach is better than hardcoding _TCHAR mybuffer[128] and sprintf(mybuffer, 128, src) all through your code.
Pejo Software - Per · 06 Aug 2003, 08:01 UTC
Just a little note in case anyone missed it:
std::string actually is defined as basic_string<char> ans wstring is defined as basic_string<wchar_t> so you can use basic_string<TCHAR> if you would like to work with TCHARs.
mlepage · 06 Aug 2003, 17:49 UTC — True
True. Another reason to use your own class, or std::basic_string, is that it acts as a container to manage memory for you. So you can have a function that does something like this:

mystring
getAbsoluteFileName(
const mystring& relativeFileName);

and not worry about who's going to delete the memory used by the return value. basic_string works the same.

I consider using raw pointers like this to be bad style:

_TCHAR*
getAbsolueteFileName(
const _TCHAR* pRelativeFileName);
PejoSoftware wrote:
Just a little note in case anyone missed it:
std::string actually is defined as basic_string<char> ans wstring is defined as basic_string<wchar_t> so you can use basic_string<TCHAR> if you would like to work with TCHARs.


Yeah thats exactly how I ended up using strings. The base library is just so darn flexable, kinda nice. =)