| | |
This may be a stupid question....
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Dec 2004
Posts: 489
Reputation:
Solved Threads: 5
•
•
•
•
Originally Posted by Dave Sinkula
Neither. An array of char that ends with a terminating null byte is a c-style string. A single char thus can never be a string.
And an uninitialized char data[]; is an incomplete type.
And 'operator<<' not implemented in type 'istream' for arguments of type 'char *'.
umm so can you give me an example of a string?
i found these in my text book under strings:
char string1[10];
char string2[] = "Hello";
cout << string2; // displays Hello....
-------------------------------------------------------------------------
Or is this a string?
char string[4];
cin.getline(string, 4, '\n');
>umm so can you give me an example of a string?
Do you see how each of these is different from your previous data?
>Or is this a string?
C++ Syntax (Toggle Plain Text)
char string1[10]; // maybe, but not yet char string2[] = "Hello"; // yes
>Or is this a string?
C++ Syntax (Toggle Plain Text)
char string[4]; // maybe, but not yet cin.getline(string, 4, '\n'); // yes now, if call was successful
String handling in C++ is NOT generally to be done using char[] or char*, but using the class string which is available in <string>.
Far easier and more safe.
So instead of the code you have you'd simply do
Far easier and more safe.
So instead of the code you have you'd simply do
C++ Syntax (Toggle Plain Text)
string s; cin << s;
and for your m8:char data; --> is a character variable NOT a string. When Dave Sinkula says "maybe not yet" he is reffering to the fact that
char data[10] is an ARRAY of characters. if and ONLY if the last is '\0' then it is a string
I agree jwenting that the ANSI string class is MUCH easier to use and works with stream operators >> and <<.
Heres one though: that char data;
if data was '\0' that could be an EMPTY string
char data[10] is an ARRAY of characters. if and ONLY if the last is '\0' then it is a string
I agree jwenting that the ANSI string class is MUCH easier to use and works with stream operators >> and <<.
Heres one though: that char data;
if data was '\0' that could be an EMPTY string
http://sales.carina-e.com
no www
no nonsense
coming soon to a pc near you! :cool:
no www
no nonsense
coming soon to a pc near you! :cool:
![]() |
Similar Threads
- Python bug??? Or just a stupid question? (Python)
- n00b question linked to bits :rolleyes: (Assembly)
- Stupid question about java.exe (Java)
- I know I'll sound stupid but... (Geeks' Lounge)
- a stupid question!!! (Windows Software)
- Another photoshop question! (Graphics and Multimedia)
- Stupid Newbie Question (C)
- Ive got a question that needsa answerin. (Search Engine Optimization)
Other Threads in the C++ Forum
- Previous Thread: Keyboard input or "stuck in a loop"
- Next Thread: queue , memory, 32k please
| Thread Tools | Search this Thread |
api array based binary bitmap c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






