|
 |
|
 |
03-14-2003, 01:46 PM
|
#1 (permalink)
|
|
Registered User
Join Date: Mar 2003
Location: Home.
Posts: 5
|
String Library
Ay peeps, anyone know where I can download a good string library? I'm using MS Visual C++. Thanks.
|
|
|
03-14-2003, 02:24 PM
|
#2 (permalink)
|
|
Code Monkey
Join Date: Feb 2003
Location: Netherlands
Posts: 89
|
VC++ should already have a string library.
Code:
#include <string>
std::string="test";
int main(void)
{
return 0;
}
Try running this, It should work.
|
|
|
03-14-2003, 02:32 PM
|
#3 (permalink)
|
|
Registered User
Join Date: Mar 2003
Location: Home.
Posts: 5
|
No dice. I think awhile back I toyed with my string libraries for a class, but I don't remember what all I might've done.
Just for good measure, :rock:
|
|
|
03-14-2003, 02:35 PM
|
#4 (permalink)
|
|
Code Monkey
Join Date: Feb 2003
Location: Netherlands
Posts: 89
|
No dice what? Errors? Can't find it? What? 
|
|
|
03-14-2003, 02:51 PM
|
#5 (permalink)
|
|
LOAD "*",8,1
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
|
with a little correction, it works fine for me in visual studio 6 and gcc.
Code:
#include <string>
std::string str = "test";
int main(void)
{
return 0;
}
|
|
|
03-14-2003, 03:05 PM
|
#6 (permalink)
|
|
Registered User
Join Date: Mar 2003
Location: Home.
Posts: 5
|
The good old
C:\Fee's\C++\junk.cpp(7) : error C2065: 'string' : undeclared identifier
C:\Fee's\C++\junk.cpp(7) : error C2146: syntax error : missing ';' before identifier 'name'
C:\Fee's\C++\junk.cpp(7) : error C2065: 'name' : undeclared identifier
using the code by joe_bruin, and declaring
string name;
Still :rock:
|
|
|
03-14-2003, 03:09 PM
|
#7 (permalink)
|
|
Regular Contributor
Join Date: Feb 2003
Posts: 120
|
I don't have VS or VC++, so I'm not sure if this will work. but try #include <cstring>
|
|
|
03-14-2003, 04:53 PM
|
#8 (permalink)
|
|
Code Monkey
Join Date: Feb 2003
Location: Netherlands
Posts: 89
|
Right Joe i forgot the variable name.
Anyway, Try this then,
Code:
#include <iostream>
#include <string>
using namespace std;
string test="abc";
int main(void)
{
return 0;
}
|
|
|
03-15-2003, 08:10 AM
|
#9 (permalink)
|
|
Registered User
Join Date: Mar 2003
Location: Home.
Posts: 5
|
Travis Dane, :rock:
That worked and I thank you. Do you know what the namespace is, and why I would have to use it if I'm using string. Shouldn't all the info for string be in <string>?
Thanks again bro.
|
|
|
03-15-2003, 08:21 AM
|
#10 (permalink)
|
|
Code Monkey
Join Date: Feb 2003
Location: Netherlands
Posts: 89
|
All of the ANSI Standard Functions and Classes are stored in
the namespace "std". To learn what a Namespace is head over
to the Namespace Tutorial.
|
|
|
03-15-2003, 11:04 AM
|
#11 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
Quote:
|
I think awhile back I toyed with my string libraries for a class...
|
Toying with the standard library is (conceptual) not a good idea anyway.
Next time when you have the urge to "toy" with the standard library, just derrive a class from your lib of interest.
Note that all the methods in the original lib are virtual. So you can override all the methods in your new class to shape it like you wish.
EXAMPLE:
// test_CmyString.cpp
#include <string>
using namespace std;
//First we make our experimental class, derrived
//from the original string library.
class CmyString : public string
{
/* Implement here your experiments.
Note that all the methods are inherited by CmyString, so you
still use them. And you can add your own insights like new
methods and properties to make a "better" string class.
Make sure you are familiar with the basics of inherritance
before you start with this.
*/
};
int main ()
{
// You can use here your new invention
return 0;
}
|
|
|
03-15-2003, 11:06 AM
|
#12 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
Is c++ cool or what? 
|
|
|
03-15-2003, 12:53 PM
|
#13 (permalink)
|
|
Registered User
Join Date: Mar 2003
Location: Home.
Posts: 5
|
Indeed. Interesting note, however.
#include <iostream>
#include <string>
using namespace std;
string test="abc";
int main(void)
{
return 0;
}
This code compiles. However, if I try to cout test, it says no go.
I added the line cout << test << endl; before the return 0. This is what I got :
C:\Fee's\C++\junk.cpp(9) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)
Any guesses?
Thanks so far fer all yer help.
|
|
|
03-15-2003, 01:47 PM
|
#14 (permalink)
|
|
Code Monkey
Join Date: Feb 2003
Location: Netherlands
Posts: 89
|
Hm, It compiles fine with me. But try this,
Code:
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
string test="abc";
int main(void)
{
cout << test.c_str() << endl;
getch();
return 0;
}
|
|
|
03-15-2003, 01:53 PM
|
#15 (permalink)
|
|
[code][/code] enforcer
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
|
You are using Visual C++ 6? If so, then it should work unless you have messed up your files. Like, moving them around and stuff. Or you messed up the dependencies.
Anyways, a last test (though conceptual totally irrelevant at this very moment!!):
Place : string test="abc";
before your cout statement, in your main() method.
Though it is clear (based upon the output error) that your compiler does not locate your string header file correctly.
This happens when you move the standard library OR mess them up OR declare vars and methods on the wrong spot. The latter case (declaring stuff on the wrong spot) is not the case clearly, since your code is correct.
UNINSTALL VC++ 6 completely and then RE-INSTALL.
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -8. The time now is 12:50 AM.
|
Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
|
 |
|