By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,302 Members | 1,429 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,302 IT Pros & Developers. It's quick & easy.

Help with characters and strings

P: 3
I need a program that displays a message indicating if a portion of a string begins with another string. The program should determine if the last name portion of the name begins with the search text. If the last name begins with the search text, it should display the message “The last name begins with “ followed by a space and the search text. If the characters in the last name come after the search text, it should display the message “The last name comes before “ followed by a space and the search text.
This is what I have so far, but I am totally stumped at what to do.

#include <iostream>
#include <string>

using namespace std;

int main()
{
//declare variables
string name = "";
string searchFor = "";


//get the search name
cout << "Enter name (first name followed by a space and the last name): ";
getline(cin, name);

//get the search text
cout << "Enter one or more characters as the search text (9 to end program): ";
getline(cin, searchFor);

while (searchFor != "9")
{

//locate the space in the search name
string name = "";
cout << name.find(name, 2);

//compare the search text to the characters located after the space in the search name
searchFor.compare(2, 5, name);

//display appropriate message


//get the search text
cout << "Enter one or more characters as the search text (9 to end program): ";
getline(cin, searchFor);
} //end while

return 0;
} //end of main function
Nov 7 '06 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.