•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 427,851 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,729 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 1878 | Replies: 7
![]() |
•
•
Join Date: Dec 2004
Posts: 465
Reputation:
Rep Power: 4
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?
char string1[10]; // maybe, but not yet char string2[] = "Hello"; // yes
>Or is this a string?
char string[4]; // maybe, but not yet cin.getline(string, 4, '\n'); // yes now, if call was successful
•
•
Join Date: Nov 2004
Location: Netherlands
Posts: 5,752
Reputation:
Rep Power: 18
Solved Threads: 199
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
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:
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Probably a stupid question but... (Windows NT / 2000 / XP / 2003)
- 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



Linear Mode