find(); Help!

I want to put the cursor at the begin of the found word.

This is string!
search: string
String is at position 0.

output. |This is string.

The cursor should be at position 0.
Thanks for the help.
Janlan

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main ()
{

	
	
	string myString;
        cout<<"Enter your text: \n";
        getline(cin, myString);
	string stringFinder;

	cout<<"Enter the word that you want to find: ";
	getline(cin, stringFinder);

	string::size_type tip1 = myString.find(stringFinder, 0); //searching seek and destry :D
	
	if(tip1 != string::npos) {
		cout<<"The word "<<stringFinder<<" is found at position "<<tip1<<"."<<endl;
	}
	else {

		cout<<"Could not find the word "<<stringFinder<<"."<<endl;
	}

cin.get(); cin.get();
return 0;
}

Last edited on
I just copied and pasted the above code and it worked fine for me...
You can use seekg() i think
Topic archived. No new replies allowed.