Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 26th, 2006, 8:18 PM   #11
Seif
Hobbyist Programmer
 
Seif's Avatar
 
Join Date: Jan 2006
Location: UK
Posts: 215
Rep Power: 3 Seif is on a distinguished road
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.
Seif is offline   Reply With Quote
Old Mar 26th, 2006, 8:47 PM   #12
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Mar 26th, 2006, 9:55 PM   #13
PPoA
Programmer
 
PPoA's Avatar
 
Join Date: Mar 2006
Location: Tennessee
Posts: 41
Rep Power: 0 PPoA is on a distinguished road
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.
PPoA is offline   Reply With Quote
Old Mar 27th, 2006, 2:07 AM   #14
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by PPoA
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.
No, myString = NULL is even illegal, (at least I thought so).
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
nnxion is offline   Reply With Quote
Old Mar 27th, 2006, 6:21 AM   #15
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Mar 27th, 2006, 9:30 AM   #16
Soulstorm
Hobbyist Programmer
 
Soulstorm's Avatar
 
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 243
Rep Power: 3 Soulstorm is on a distinguished road
Quote:
Originally Posted by PPoA
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.
It seems there is a misunderstanding here. There is the "string" that is a actually an array of characters, and the "string" that is produced by the "string" class. Teachers often use the term "string" for the first occasion, which often leads to wrong impressions about what an actual string is.

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)
Soulstorm is offline   Reply With Quote
Old Mar 27th, 2006, 9:54 AM   #17
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Quote:
So, i guess it's a Microsoft thing.
You missed a post; it works with VC++ 2005. I suspect it's an age thing. VC6.0 predates the standard.
__________________
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
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:43 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC