Sentence : Hello , FindStringInSentence = ello , EditString = i; Output = Hi

Sentence : Hello , FindStringInSentence = ello , EditString = i; Output = Hi

please help me this is what i have idk how to continue well we enter string then we enter which part we want to edit , and write what will be writen on edited place . as the tittle says pls dont do other code try to fit it into what i have ty.

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
#include <iostream>
#include <string>

using namespace std;

int main (){
string Sentence;
string FindString;
int LengthSentence = Sentence.length();
int LengthFindString = FindString.length();

cout <<"Enter sentence : ";

getline(cin,Sentence);

cout<<"Enter string that u want edit : ";

cin >> FindString;

for (int i = 0; i<=LengthSentence; i++){
	for (int j = 0; j<=LengthFindString; j++){
		while(FindString[1]!=Sentence[i]){
			
		}
	for (int s = 0; s<=LengthFindString; s++){
		if ()
	}
											 }
									   }
		  }
(Sorry please, its really difficult to understand what you're trying to say for a non-native English speaker like me.)

But as a first tip: Your loop bodies will only be executed once, because LengthSentence and LengthFindString stay constantly zero.
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
33
34
35
#include <iostream>
#include <string>

int main()
{
   // enter string
   std::string str ;
   std::cout << "string? " ;
   std::getline( std::cin, str ) ;

   // enter which part we want to edit
   std::string find_str ;
   std::cout << "find? " ;
   std::getline( std::cin, find_str ) ;

   // what will be written on edited place
   std::string replacement_str ;
   std::cout << "replace with? " ;
   std::getline( std::cin, replacement_str ) ;

   // find the edit string
   // http://www.cplusplus.com/reference/string/string/find/
   const std::string::size_type pos = str.find( find_str ) ;
   if( pos != std::string::npos ) // if it was found
   {
       // http://www.cplusplus.com/reference/string/string/substr/
       std::string modified_str = str.substr( 0, pos ) // the part before the find string
                                  + replacement_str // followed by the replacement string
                                  + str.substr( pos + find_str.size() ) ; // followed by the part after the find string

       std::cout << "original string: " << str << '\n'
                 << "modified string: " << modified_str << '\n' ;
   }
   // note: put the above in a loop to replace all occurrences
}
Topic archived. No new replies allowed.