pls help me...i wnt to know how to delete a word from a string...cant make it out..pls help...

Use substr to extract the characters before the word, after that use it again to extract the raw of characters after the word, then join both strings by summing them.

Example:

string sentence="blah blah blah";
string before=sentence.substr(0,5);
string after=sentence(10,14);
string withoutTheWord=before+after;

Are you using a std::string? If so, you can use a combination of the find and erase methods:

std::string s( "The quick brown fox jumps over the lazy dog" );

std::cout << s << std::endl;

std::string::size_type position = s.find( "jumps" );
s.erase( position, 6 );  // Use a size of 6 to include the extra space after the word

std::cout << s << std::endl;

If you're not allowed to use std::string then you will have to use the functions in <cstring>. You can use std::strstr to find a substring in a C-style char array. Then you can use std::strcpy to build a new string with the missing parts.

Finally, if you're not allowed to use either of these two methods, then you'll have to write your own function to do the comparison.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.