std::string manipulation help

Started by
19 comments, last by Squishy 19 years ago
I have 2 std::strings called buffer and Test. I want to see if Test appears in buffer i was just wondering how this could be done in c++
Advertisement
Straight out of the docs. Took about 15 seconds...

string::find

Searches a string in a forward direction for the first occurrence of a substring that matches a specified sequence of characters.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
buffer.find( Test) returns the position of first match or std::string::npos
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
Right this seems to be going in the right direction but im still not their yet

while (! FILE.eof() )
{
FILE.getline (buffer,1000);
if (std::string::find(buffer,Test))
DO THIS
else
DO THAT



}

This is basically hwat im trying to get it to perform im very new to c++ and would apreciate any feed back the previouse other replys i wasnt sure how to implement
from the top of my head
while( FILE.getline( buffer, 1000))  if( buffer.find( Test) != std::string::npos)  {  //do this  }  else  {  //do that  }
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
i tryed that i currently am getting the error

error C2228: left of '.find' must have class/struct/union type
well that would imply that buffer isn't a std::string then...
HardDrop - hard link shell extension."Tread softly because you tread on my dreams" - Yeats
ok thanx for your time i will go back and check what buffer is
Ok im officially hopeless i have no idea hwta im doing i should never have taken this on but now its annoying me

This is the whole function

void IRCBot::Remscans(std::string Test, std::string nick)
{
char buffer[1000];
std::ifstream File("SCANS");

while (! File.eof() )
{
File.getline (buffer,1000);
if( buffer.find( Test) != std::string::npos)
SEND_NOTICE(nick, "WORKING");
else
SEND_NOTICE(nick, "NOT WORKING");



}
}

im probebly doing somthing fundementaly stupid i usually am
Why are you declaring buffer as an array of 1000 characters, rather than as a std::string?

This topic is closed to new replies.

Advertisement