![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: UK
Posts: 215
Rep Power: 3
![]() |
lol typical that it would work on every compiler but mine
have been meaning to get the 2005 express edition, however im too low on disk space at current... as well as my graphics card breaking down on me earlier this evening. ![]() |
|
|
|
|
|
#12 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
I certainly recommend you get the 2005 when you have the disk space, but don't dump the 6.0. The 2005 doesn't have old GUI support (like MFC, old resource editor) and is very .NET centric when you move away from console apps. Nothing exactly wrong with .NET, except I don't want it forced on me for every dam' move. When you do get it, get the SDK if you don't already have it, and put it on your include and lib paths. I also have the DDK tied into it.
Meanwhile, nothing wrong with myString = "" or using the erase method.
__________________
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 |
|
|
|
|
|
#13 |
|
Programmer
Join Date: Mar 2006
Location: Tennessee
Posts: 41
Rep Power: 0
![]() |
Couldn't you also do myString='\0' or myString=NULL? Are those still allowed in C++? Seems the teacher says they are trying to phase out the '\0' and replace it with NULL or vice versa.
|
|
|
|
|
|
#14 | |
|
Programming Guru
![]() Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5
![]() |
Quote:
On a lot of compilers it will result in an ambigious overload of the = operator. myString='\0' will put a null character as the first letter. #include <iostream>
#include <string>
using namespace std;
int main()
{
string myString = "hello";
cout << "1: " << myString << "\nlength: " << myString.length() << endl << endl;
myString = "";
cout << "2: " << myString << "\nlength: " << myString.length() << endl << endl;
myString = "world";
cout << "3: " << myString << "\nlength: " << myString.length() << endl << endl;
myString.erase();
cout << "4: " << myString << "\nlength: " << myString.length() << endl << endl;
myString = "how are";
cout << "5: " << myString << "\nlength: " << myString.length() << endl << endl;
myString = '\0'; // will result in a length of 1, std::string doesn't need to be zero terminated
cout << "6: " << myString << "\nlength: " << myString.length() << endl << endl;
myString = "\0hello"; // this will, however, result in a length of 0
cout << "7: " << myString << "\nlength: " << myString.length() << endl << endl;
myString = "you?";
cout << "8: " << myString << "\nlength: " << myString.length() << endl << endl;
//myString = NULL; // Beside the fact that std::string manages its own memory, this will result in an ambigious overload of the = operator
cout << "9: " << myString << "\nlength: " << myString.length() << endl << 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 Last edited by nnxion; Mar 27th, 2006 at 2:19 AM. Reason: formatting |
|
|
|
|
|
|
#15 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Possibly PPoA doesn't realize that a C-string is an array of char and a C++ string is an object defined by a specific class. As for what NULL is, regarding the two languages, there's a recent thread that covers part of it, as regards pointers.
__________________
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 |
|
|
|
|
|
#16 | |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 243
Rep Power: 3
![]() |
Quote:
What we are talking about here is the string that is produced by the "string" class, which is found in the <string> library, which in turn is part of the STL. As for the original question: clear() works for me in both devc++ and Xcode on OS X. So, i guess it's a Microsoft thing.
__________________
Project::Soulstorm (personal homepage) |
|
|
|
|
|
|
#17 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
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 |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|