Solved

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

Posted on 2006-06-15
2
229 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
Comment Utility
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
Comment Utility
thanks, that was perfect
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now