You maybe able to use normal variables when working with arrays or even references instead of pointers. However, pointers are usually the most complex part of C/C++ and I am hoping with enough example, I can help others understand how to use them and become comfortable using them especially that a lot of existing C/C++ code uses pointers (mainly C), so when you read code written in C/C++ you can easily understand it ;)
The label of this video is misleading the actions performed in this video. This is a great video but it should be labeled as "How to remove ....... from a character in C/C++" I was looking for something that can actually deletes symbols from a string. int main () { string s : "Hello!" cout
string is not a basic (intrinsic) datatype in C++. It is actually a class written as part of std namespace and is not considered a basic type. strings in C/C++ are actually character arrays. You're looking for something like this, which I don't like : string str="Hello!!!!"; std::size_t found = str.find("!"); while (found != std::string::npos) { str.replace(found, 1, ""); found = str.find("!"); } My video shows you how to do it fine in both C/C++, so you can use my approach above, which doesn't require use of classes like std::string Or in my other video on removing a single char, you can do this: char s[] = "H!ello!!!"; //this is a string in C/C++ int index = 0; for (int i = 0; i < strlen(s); ++i) if (s[i] != '!') s[index++] = s[i]; s[index] = '\0'; This is more efficient if you care about performance.
The title is not misleading. I think you don't know that characters arrays that are NULL-termintaed is how you implement strings in C/C++. The string class you mentioned is not a built-in type
This video was very helpful and fun to follow along!! Thanks for posting! Two thumbs up
Thank you!
Thanks again.Easy to grasp and remember - Brilliant!
Thank you and much appreciated :)
why use pointer rather than passing normal variable or just a refference?
You maybe able to use normal variables when working with arrays or even references instead of pointers. However, pointers are usually the most complex part of C/C++ and I am hoping with enough example, I can help others understand how to use them and become comfortable using them especially that a lot of existing C/C++ code uses pointers (mainly C), so when you read code written in C/C++ you can easily understand it ;)
The label of this video is misleading the actions performed in this video. This is a great video but it should be labeled as "How to remove ....... from a character in C/C++"
I was looking for something that can actually deletes symbols from a string.
int main ()
{
string s : "Hello!"
cout
string is not a basic (intrinsic) datatype in C++. It is actually a class written as part of std namespace and is not considered a basic type. strings in C/C++ are actually character arrays.
You're looking for something like this, which I don't like :
string str="Hello!!!!";
std::size_t found = str.find("!");
while (found != std::string::npos)
{
str.replace(found, 1, "");
found = str.find("!");
}
My video shows you how to do it fine in both C/C++, so you can use my approach above, which doesn't require use of classes like std::string
Or in my other video on removing a single char, you can do this:
char s[] = "H!ello!!!"; //this is a string in C/C++
int index = 0;
for (int i = 0; i < strlen(s); ++i)
if (s[i] != '!')
s[index++] = s[i];
s[index] = '\0';
This is more efficient if you care about performance.
The title is not misleading. I think you don't know that characters arrays that are NULL-termintaed is how you implement strings in C/C++. The string class you mentioned is not a built-in type
saved my life!