TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: ALL
from: JAMIE KOWINSKY
date: 1997-10-08 20:06:00
subject: Char[] Strings

I used to program in C and used an array of chars for strings, Now I'm
using C++ and find that strings are now a class with shinny new operations
to preform on them.  However I have a few questions about using the old 
C style strings in C++.
For various reasons there are times when I need to use an array of chars for 
a string.  Can I safely use cin on it? for example, is cin << somestring; 
safe?
By safe I mean that The array has to have a null char in it to terminate it.
If the char array is 5 elemets and someone types in a huge string what will
happen?  I'm assuming since cin doesnt know the size of my array that it will
just write all thoese bytes over whatever happens to be in memory after the 
array of chars.
Also, I need a bit of a refresher course with char array strings, One point I 
can't quite remember is the max length of a string that can be entered into 
n
arary of a given size, is it size-1? For example, if an array has 3 elements 
(0-3) I cannot store "the" as there will be no null character, but "hi" is ok 
as it would be "Hi"+nullch (3 elements)
thanks for any info you may be able to provide.
Prehaps theres a FAQ for something like this?
l8tr
-Jam
... Has anybody seen my tagline? It about 70 characters long and sarcastic.
--- FMail/386 1.02
---------------
* Origin: KastlerocK + Jeannette, PA + 412.527.3749 (1:129/230)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.