need to find from either strings and print

I have just started to program an I am stuck in one problem. So I have a txt file that contains a single line: i.e. 13digitnumber 13digitnumber letter randomstring letter(could be same) The question is I need to find the letter of which there could be from 3 different choices and print. I have decided to have seperate function for this. so far I have done:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  string isWanted(string & line1)
{

if (line1.find_first_of("sam"))
{ 
    line1 = ("sam");
}
else if (line1.find_first_of("luke"))
{
    line1 = ("luke");
}
else if (line1.find_first_of("chris"))
{
    line1= ("chris");
}
return line1;
}


For out put I only get sam although its different letter. Thanks in advance
The question is I need to find the letter of which there could be from 3 different choices and print

Your code snippet doesn't match the description, it is searching for randomstring not a letter
Lets say your file contains
1234567890123 1234567890123 A ABCDEFG V

What part would you want to search for ?
1234567890123 1234567890123 sam WELCOME chris
1234567890123 1234567890123 chris WELCOME sam
1234567890123 1234567890123 luke WELCOME sam

so the text could be either of 3 above lines.

so i first need to scan for first occuring letter from either sam chris or luke
and return that letter.
A very crude way to read the file into different parts.
1
2
3
4
5
6
ifstream src("data.txt"); // please add error checking
string dummy, name1, msg, name2;
while (src >> dummy >> dummy >> name1 >> msg >> name2)
{
  // now check it name1 or name2 contains the wanted name  or letter 
}
Topic archived. No new replies allowed.