Solved

Issue with strings containing numbers in set container

Posted on 2014-03-25
2
236 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
2 Comments
 
LVL 24

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now