Jump to content
  • Advertisement
Sign in to follow this  
Squishy

std::string manipulation help

This topic is 4834 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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++

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
i tryed that i currently am getting the error

error C2228: left of '.find' must have class/struct/union type

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Why are you declaring buffer as an array of 1000 characters, rather than as a std::string?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!