![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Arrays
In C/C++, arrays (including 'C-strings', arrays of char) are not atomic objects that can be assigned or compared with the =, ==, >=, etc., operators.
The statement, "if (myString == "abcd"), will, in fact, compare the two pointers, NOT the contents referenced by those pointers. Just thought you'd like to know, in case you don't read (or comprehend) the multidinous threads on the forum that impart this fact.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Apr 2005
Posts: 218
Rep Power: 4
![]() |
Phew...for a minuite there I thought you were asking for help
![]() |
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Hey, I ask for help when I can't find the answer by searching! (Admittedly, I search other forums as well as this one, I just don't recommend that out loud to the members here.)
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Oct 2005
Posts: 211
Rep Power: 3
![]() |
What's the context for this spontanious outburst? Has this been plagueing your thoughts recently? Or have questions like these been plagueing this (or other) forums?
-MBirchmeier |
|
|
|
|
|
#5 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
|
|
|
|
|
|
#6 |
|
Hobbyist Programmer
|
So this means you can't do something like this?:
string message[1]; if (message[1] == "whatever") etc. That won't work?
__________________
And there was much rejoicing... Yay.... |
|
|
|
|
|
#7 | ||
|
Professional Programmer
|
Quote:
__________________
▄▄▄▄ Quote:
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it. Download Code::Blocks now! ▄▄▄▄ |
||
|
|
|
|
|
#8 | ||
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
Edit: Quote:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string message[1];
message[0] = "hello";
if (message[0] == "hello")
cout << "hello" << endl;
else
cout << "bye" << endl;
return 0;
}
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for." -- Socrates |
||
|
|
|
|
|
#9 |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: UK
Posts: 215
Rep Power: 3
![]() |
nope, use the string compare function.
string message[1]; if (strcmp(message[0], "whatever") == 0) etc Must admit I understand where Dawai is coming from, have seen a couple of posts recently where there seems to be confusion with pointers and arrays. Was going to refer them to Dawai's tutorial on pointers as I'm not too up to scratch on them myself. |
|
|
|
|
|
#10 |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: UK
Posts: 215
Rep Power: 3
![]() |
bah missed those last 2 posts by jayme and nnxion sorry.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|