No. It's unsafe, because as I stated before, there is no guarantee that the buffer will fit what you type into it. As you have it right now, strg
will hold nine characters plus the terminating character ('\0'
). If the user types a string that is ten characters or more, your program may behave erratically or it may crash, either instantly or somewhere down the road.
Instead of using cin >> strg;
, you should use cin.getline(strg, 10);
in this case, which will read a line of text that the user types, and makes sure not to fill your array anywhere past those ten characters that you can hold.