How to clear a string in c++

hello, i have something i want to ask

  1. whenever i had to use a string, i used char arr[50] or char arr[size] like that, but now i am seeing many people use the string keyword for making strings.
    like string test and it has many functions to make it much more easy to use.
    ques: should i start using string keyword for using strings or should i stick to char arr[50] type??

  2. i wanted to clear a string. i see that we can use str.clear() function for clearing a string.
    but if i have to clear a string which i made by char arr[100]; i.e delete all the contents of the string and make its length to be 0, how should i do it?

  3. i use fgets() function for inputting a string. ( which i created by char test[50])
    lets say i used fgets() for inputting a string called “test” , the user inputted “hellofriend”
    and then again i use the fgets() on the same string “test” (without it being cleared) and now the user enters “spell”
    what would the string contain then??

  1. Use a string by including <string> or <bits/stdc++.h> (pro move).
  2. Let’s say your string is called s. Simply say s = "" to clear it.
  3. You can use cin to input a string. In this case, the string get’s updated to the most recent value. Now your string test is "spell".

thank you so much for the help :slight_smile: