•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 425,909 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 1,810 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: 722 | Replies: 13
![]() |
•
•
Join Date: Jul 2008
Posts: 23
Reputation:
Rep Power: 1
Solved Threads: 0
Erm, I am a bit confused about this bit (hope I have quoted the code properly)
•
•
•
•
CPP Syntax (Toggle Plain Text)
string str = "Hello";char *cstr = &str[0];string str = "Hello";
char *cstr = &str[0];
Also this way the pointer isn“t const unlike the return value from the string::c_str() function.
(The only problem with this is that it is not a seperate char array, anything you change in cstr will also change in str).
I can remember reading something about only needing the first element of a character array when using pointers, or something similar and I think that is important here but I am more confused about char vs char* in general. I don't understand why it is necessary to use pointers here since to my untrained eye strings and arrays seem to be almost equivalent apart from the [] and the null pointer.
Also if someone could give me a quick explanation of that std:"something here" thing. I see it all over and it seems to be pretty fundamental but I haven't come across it any of the things I was taught or the beginners information I have read. From what I can see (probably wrong) it seems to be like an alternative to a header file. But isn't a header file more convenient? You only have to type it once and the code is much easier to follow (imo).
Sorry for jabbering on a bit. Everyone here seems very helpful
•
•
Join Date: Oct 2007
Posts: 232
Reputation:
Rep Power: 1
Solved Threads: 19
Everyone has a different way of writing their codes. What you may find long may be easy for someone else. I dont think from what you originally wanted pointers would be of alot of help but it can be done to.
>>Also if someone could give me a quick explanation of that std:"something here" thing
This can be used if the statement "using namespace std" has not been included in the code. All the files in the C++ standard library declare all of its entities within the std namespace. That is why someone can do something like this
>>Also if someone could give me a quick explanation of that std:"something here" thing
This can be used if the statement "using namespace std" has not been included in the code. All the files in the C++ standard library declare all of its entities within the std namespace. That is why someone can do something like this
std::cout<<"Hello";
Last edited by joshmo : Jul 24th, 2008 at 1:43 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- please help learning converting string to int (C++)
- converting from char to ASCII to char (C++)
- Splitting words from string into character array (C++)
- convert char* to double (C++)
- Stuck a bit on input (C)
- Converting without additional headers (C)
- Convert first character from lowercase to uppercase? (C)
- Help with Class, stuck. (C++)
- Help with fstream (C++)
- reading a file into code (Java)
Other Threads in the C++ Forum
- Previous Thread: queue ?
- Next Thread: *.stl files


Linear Mode