how to do this like it should ??

Hello,

I'm starting to learn how to program in c++.
I use now
for (inti=0,i<20,i++){string[i]=0x00;}
to "reset" a string to zero.

How is the correct way to do that ?

lapijnAsked:
Who is Participating?
 
Jaime OlivaresConnect With a Mentor Software ArchitectCommented:
Andrey_go answer will be enough, assumming you are working with a char array (I guess it is because 'string' name), because in stardard C, all string are zero-terminated.

string[0]=0;  could be simplified to:
*string = 0;

'string' is not a good name because there is some library called STL that uses a data type called string.
0
 
Andrey_goConnect With a Mentor Commented:
string[0]=0; should be enough
0
 
InteractiveMindCommented:
use a char array, instead of string.

0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
lapijnAuthor Commented:
thanks teuntje.
0
 
lapijnAuthor Commented:
OK, jaime_olivares. Thanks all.
0
All Courses

From novice to tech pro — start learning today.