Click here to Skip to main content
16,019,983 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Screen Sizes Pin
Hamid Taebi28-Aug-06 4:20
professionalHamid Taebi28-Aug-06 4:20 
Questionwclen returning wrong value Pin
Waldermort27-Aug-06 8:37
Waldermort27-Aug-06 8:37 
AnswerRe: wclen returning wrong value Pin
Nibu babu thomas27-Aug-06 17:25
Nibu babu thomas27-Aug-06 17:25 
GeneralRe: wclen returning wrong value Pin
Waldermort27-Aug-06 20:13
Waldermort27-Aug-06 20:13 
QuestionAdding Components and control in VC2005 Pin
pimpim323227-Aug-06 8:08
pimpim323227-Aug-06 8:08 
AnswerRe: Adding Components and control in VC2005 Pin
pimpim323227-Aug-06 8:42
pimpim323227-Aug-06 8:42 
GeneralRe: Adding Components and control in VC2005 Pin
Wes Aday27-Aug-06 15:12
professionalWes Aday27-Aug-06 15:12 
Questionsearching in strings [modified] Pin
jon-8027-Aug-06 6:44
professionaljon-8027-Aug-06 6:44 
This function should count the number of occurrences of strSearch within sentence. The compiler doesn't like it when a string variable is given instead of a char for functions such as strstr, strlen...

unsigned int CSentenceList::searchInSentence(const string* sentence, const string* strSearch)
{
char buffer[MAX_SENTENCE_LENGTH + 1] = {0};
memcpy(buffer, sentence, MAX_SENTENCE_LENGTH);

char* strToken = 0;
unsigned long iWordCount = 0;
strToken = strstr(buffer, strSearch);

while (strToken !=NULL)
{
if (strlen(strToken) > 0)
{iWordCount++;
strToken += strlen(strSearch);
}

strToken = strstr(strToken, strSearch);

}
return iWordCount;
}

Errors:

cSentenceList.cpp(70): error C2664: 'strstr' : cannot convert parameter 2 from 'const std::string *' to 'const char *'

SentenceList.cpp(76): error C2664: 'strlen' : cannot convert parameter 1 from 'const std::string *' to 'const char *'

I tried (char) and (char*) but they don't work...

Within the class members of stl::string, I found the following specialization that allows the class to take advantage of library functions that manipulate objects of this type char.
char_traits<char> Class A class that is a specialization of the template class char_traits<CharType> to an element of type char.
(MSDN)

Any idea how to use them?


Is it possible to cast a string to a char, somehow?

Is it possible to use other functions to search for substrings within the string class?



Jon

p.s. sorry for the numerous q's, I'm lost...


-- modified at 12:49 Sunday 27th August, 2006
AnswerRe: searching in strings Pin
Kevin McFarlane27-Aug-06 6:55
Kevin McFarlane27-Aug-06 6:55 
AnswerRe: searching in strings Pin
Waldermort27-Aug-06 7:57
Waldermort27-Aug-06 7:57 
AnswerRe: searching in strings Pin
BlitzPackage27-Aug-06 15:40
BlitzPackage27-Aug-06 15:40 
GeneralRe: searching in strings Pin
Stephen Hewitt27-Aug-06 18:30
Stephen Hewitt27-Aug-06 18:30 
GeneralRe: searching in strings Pin
BlitzPackage28-Aug-06 7:55
BlitzPackage28-Aug-06 7:55 
Questionascii codes Pin
jon-8027-Aug-06 6:17
professionaljon-8027-Aug-06 6:17 
AnswerRe: ascii codes Pin
JWood27-Aug-06 7:39
JWood27-Aug-06 7:39 
AnswerRe: ascii codes Pin
jon-8028-Aug-06 7:41
professionaljon-8028-Aug-06 7:41 
GeneralRe: ascii codes Pin
JWood28-Aug-06 8:23
JWood28-Aug-06 8:23 
QuestionCRecordView Display Pin
ivanris27-Aug-06 5:37
ivanris27-Aug-06 5:37 
AnswerRe: CRecordView Display Pin
Mircea Puiu27-Aug-06 20:44
Mircea Puiu27-Aug-06 20:44 
GeneralRe: CRecordView Display Pin
ivanris28-Aug-06 3:29
ivanris28-Aug-06 3:29 
AnswerRe: CRecordView Display Pin
David Crow28-Aug-06 4:22
David Crow28-Aug-06 4:22 
QuestionHow to use recompiled header file? Pin
Super Lloyd27-Aug-06 4:09
Super Lloyd27-Aug-06 4:09 
AnswerRe: How to use recompiled header file? Pin
Waldermort27-Aug-06 4:35
Waldermort27-Aug-06 4:35 
QuestionToolbar Control Pin
mehrdadov27-Aug-06 2:29
mehrdadov27-Aug-06 2:29 
AnswerRe: Toolbar Control Pin
Christian Graus27-Aug-06 2:59
protectorChristian Graus27-Aug-06 2:59 

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.