Solved

is there a way to search inside a string for another string in c++?

Posted on 2006-06-15
2
246 Views
Last Modified: 2010-04-01
string temp = "hello world";

is there a way to search temp to see if the word "world" exists within it?

thanks
0
Comment
Question by:rspiege1
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 16915479
Sure, e.g.

string temp = "hello world";

int pos = temp.find("world");

if (-1 != pos) {

// "world" has been found

} else {

// nothing found
}
0
 

Author Comment

by:rspiege1
ID: 16915978
thanks, that was perfect
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

785 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