Click here to Skip to main content
15,914,488 members
Home / Discussions / ATL / WTL / STL
   

ATL / WTL / STL

 
GeneralRe: Direct3D Types as interface parameters Pin
Aschratt21-Feb-10 6:24
Aschratt21-Feb-10 6:24 
QuestionHow to create EXE setup file using VS2005,VS2008 Pin
am 20096-Feb-10 6:14
am 20096-Feb-10 6:14 
AnswerRe: How to create EXE setup file using VS2005,VS2008 Pin
KingsGambit6-Feb-10 6:38
KingsGambit6-Feb-10 6:38 
AnswerRe: How to create EXE setup file using VS2005,VS2008 Pin
LunaticFringe6-Feb-10 7:58
LunaticFringe6-Feb-10 7:58 
Questionvector of strings, find all matches Pin
ekimpl3-Feb-10 23:54
ekimpl3-Feb-10 23:54 
AnswerRe: vector of strings, find all matches Pin
Nuri Ismail4-Feb-10 0:14
Nuri Ismail4-Feb-10 0:14 
GeneralRe: vector of strings, find all matches Pin
ekimpl4-Feb-10 0:38
ekimpl4-Feb-10 0:38 
GeneralRe: vector of strings, find all matches Pin
Nuri Ismail4-Feb-10 3:51
Nuri Ismail4-Feb-10 3:51 
ekimpl wrote:
Now that I see Your solution I don't know if I understand the concept of iterators correctly.

This[^] is a good place for understanding them. Smile | :)

ekimpl wrote:
I thought that t_vec::const_iterator i = std::find(v.begin(), v.end(), searched_string) would result in i pointing only to the matches

In general iterators are used to access elements of a sequence, and can be used in a similar manner to pointers. Consequently an iterator can point only to one concrete element of a sequence at current time, just like a pointer.

ekimpl wrote:
So if I wanted to know all the indexes of found matches outside of FindNumber, it should return an array of found indexes, yes ?

Yes, but using indexes is OK only for a std::vector container, because it supports RandomAccessIterator so, you could easily use operator[].
If you later decide to change the container type (for example to std::list) then indexes will not work. So in general it is better to fill an array with iterators each pointing to exact matched element. And finally it is not a good idea to return a whole array, I'd prefer accepting this array by reference in my function.

Here is a modified example for your code which will fill indexes of the matched elements:
bool FindNumber(const std::vector<sStringStruct>&v, const std::string& nString, std::vector<int>& indexes)
{
	bool found = false;
	sStringStruct searched_string = sStringStruct(nString);
	
	const int vec_size = v.size();
	for(int i = 0; i < vec_size; i++)
	{
		if(v[i] == searched_string)
		{
			indexes.push_back(i);
			found = true;
		}
	}
	
	// Say if we found something or not
	return found;
}

        // And you can use the function this way:
        std::vector <sStringStruct> vec;
        vec.push_back(sStringStruct("xxxx"));
	vec.push_back(sStringStruct("aaaa"));
	vec.push_back(sStringStruct("bbbb"));
	vec.push_back(sStringStruct("cccc"));
	vec.push_back(sStringStruct("aaaa"));

	std::vector<int> indexes;
	bool found = FindNumber(vec, "aaaa", indexes);
	if(found)
	{
		const int indexes_size = indexes.size();
		for(int i = 0; i < indexes_size; i++)
		{
			std::cout << "MATCH:" << vec[indexes[i]].m_nString << std::endl;
		}
	}


You asked about indexes, so I removed the usage of std::find algorithm.
But as I've said before, this solution works only for std::vector.
More general solution is to fill an array of iterators using std::find algorithm.

I hope this helps. Smile | :)

Regards
GeneralRe: vector of strings, find all matches Pin
ekimpl4-Feb-10 4:03
ekimpl4-Feb-10 4:03 
GeneralRe: vector of strings, find all matches Pin
Nuri Ismail4-Feb-10 4:07
Nuri Ismail4-Feb-10 4:07 
QuestionClient Blocking Event Sink Pin
Anthony98871-Feb-10 4:30
Anthony98871-Feb-10 4:30 
AnswerRe: Client Blocking Event Sink Pin
Stuart Dootson1-Feb-10 11:03
professionalStuart Dootson1-Feb-10 11:03 
QuestionSplitterWindow change message? [modified] Pin
Member 381982121-Jan-10 11:41
Member 381982121-Jan-10 11:41 
AnswerRe: SplitterWindow change message? Pin
Stuart Dootson21-Jan-10 22:53
professionalStuart Dootson21-Jan-10 22:53 
AnswerRe: SplitterWindow change message? Pin
Jonathan Davies22-Jan-10 2:36
Jonathan Davies22-Jan-10 2:36 
GeneralRe: SplitterWindow change message? Pin
Stuart Dootson22-Jan-10 2:51
professionalStuart Dootson22-Jan-10 2:51 
QuestionI need an ebay program Pin
totolcm13-Jan-10 2:19
totolcm13-Jan-10 2:19 
QuestionQuery to copy the table with Data and Constraints in SQL Server Pin
siddisagar6-Jan-10 0:56
siddisagar6-Jan-10 0:56 
AnswerRe: Query to copy the table with Data and Constraints in SQL Server Pin
LunaticFringe6-Jan-10 1:05
LunaticFringe6-Jan-10 1:05 
GeneralRe: Query to copy the table with Data and Constraints in SQL Server Pin
siddisagar6-Jan-10 1:12
siddisagar6-Jan-10 1:12 
GeneralRe: Query to copy the table with Data and Constraints in SQL Server Pin
LunaticFringe6-Jan-10 2:27
LunaticFringe6-Jan-10 2:27 
QuestionATL ActiveX control embedded in Internet Explorer not receiving WM_CREATE, WM_DESTROY, WM_SHOWWINDOW messages Pin
Member 455120828-Dec-09 23:55
Member 455120828-Dec-09 23:55 
QuestionProblem in transform function Pin
ashtwin16-Dec-09 1:50
ashtwin16-Dec-09 1:50 
AnswerRe: Problem in transform function Pin
Stuart Dootson16-Dec-09 6:45
professionalStuart Dootson16-Dec-09 6:45 
GeneralRe: Problem in transform function Pin
ashtwin16-Dec-09 17:34
ashtwin16-Dec-09 17:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.