Solved

Issue with strings containing numbers in set container

Posted on 2014-03-25
2
266 Views
Last Modified: 2014-03-25
I cannot retrieve any string from a set container if the string has numbers in it. I am able to successfully retain any string that contain only characters, but if I add a string to the container that contains even one number I receive an error when trying to retrieve it using wprintf(). See my code below:

typedef basic_string<wchar_t> tstring_t;
typedef set<tstring_t> tset_t;
tset_t groupsFound;

wchar_t bufName[MAX_PATH]; (this is populated by another function)

groupsFound.insert(bufName);

_tprintf(_T("# of elements in groupsFound: %i\r\n"), groupsFound.size());

for (tset_t::iterator it=groupsFound.begin(); it!=groupsFound.end(); ++it)
{
	_tprintf(_T("%s\n"), *it);
}

Open in new window

0
Comment
Question by:tr57285
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
chaau earned 500 total points
ID: 39955031
Please use
_tprintf(_T("%s\n"), (*it).c_str());

Open in new window

Using the tstring_t class (or any other class) is never safe as a const char* replacement with the argument list in the format.
0
 

Author Closing Comment

by:tr57285
ID: 39955083
This worked perfectly, thanks
0

Featured Post

Building an interactive eFuture classroom

Watch and learn how ATEN provided a total control system solution including seamless switching matrix switch, HDBaseT extenders, PDU, lighting control to build an interactive eFuture classroom.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Determining the an SCCM package name from the Package ID
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Six Sigma Control Plans

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question