|
-
October 20th, 2010, 01:18 PM
#3
Re: is there any problem if I set a char to '\0' within a string?
You can do it, but you are undermining the system. Passing the string as an array to a C-Style API will break the API. You may have weird behavior when putting the string in a stream.
Strings hold char, but they are really supposed to represent text. If you just want a container of char, consider using a vector<char> instead. The interface will be better adapted, and your code less confusing.
Is your question related to IO?
Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|