Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 03-14-2003, 01:46 PM   #1 (permalink)
MacTool
Registered User
 
MacTool's Avatar
 
Join Date: Mar 2003
Location: Home.
Posts: 5
MacTool is on a distinguished road
String Library

Ay peeps, anyone know where I can download a good string library? I'm using MS Visual C++. Thanks.
MacTool is offline   Reply With Quote
Old 03-14-2003, 02:24 PM   #2 (permalink)
Travis Dane
Code Monkey
 
Travis Dane's Avatar
 
Join Date: Feb 2003
Location: Netherlands
Posts: 89
Travis Dane is on a distinguished road
Send a message via ICQ to Travis Dane
VC++ should already have a string library.

Code:
 #include <string>

 std::string="test";

 int main(void)
 {
   return 0;
 }
Try running this, It should work.
__________________
OpenGL, DirectX
Travis Dane is offline   Reply With Quote
Old 03-14-2003, 02:32 PM   #3 (permalink)
MacTool
Registered User
 
MacTool's Avatar
 
Join Date: Mar 2003
Location: Home.
Posts: 5
MacTool is on a distinguished road
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:
MacTool is offline   Reply With Quote
Old 03-14-2003, 02:35 PM   #4 (permalink)
Travis Dane
Code Monkey
 
Travis Dane's Avatar
 
Join Date: Feb 2003
Location: Netherlands
Posts: 89
Travis Dane is on a distinguished road
Send a message via ICQ to Travis Dane
No dice what? Errors? Can't find it? What?
__________________
OpenGL, DirectX
Travis Dane is offline   Reply With Quote
Old 03-14-2003, 02:51 PM   #5 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
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;
 }
joe_bruin is offline   Reply With Quote
Old 03-14-2003, 03:05 PM   #6 (permalink)
MacTool
Registered User
 
MacTool's Avatar
 
Join Date: Mar 2003
Location: Home.
Posts: 5
MacTool is on a distinguished road
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:
MacTool is offline   Reply With Quote
Old 03-14-2003, 03:09 PM   #7 (permalink)
alpha
Regular Contributor
 
Join Date: Feb 2003
Posts: 120
alpha is on a distinguished road
Send a message via AIM to alpha
I don't have VS or VC++, so I'm not sure if this will work. but try #include <cstring>
alpha is offline   Reply With Quote
Old 03-14-2003, 04:53 PM   #8 (permalink)
Travis Dane
Code Monkey
 
Travis Dane's Avatar
 
Join Date: Feb 2003
Location: Netherlands
Posts: 89
Travis Dane is on a distinguished road
Send a message via ICQ to Travis Dane
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;
 }
__________________
OpenGL, DirectX
Travis Dane is offline   Reply With Quote
Old 03-15-2003, 08:10 AM   #9 (permalink)
MacTool
Registered User
 
MacTool's Avatar
 
Join Date: Mar 2003
Location: Home.
Posts: 5
MacTool is on a distinguished road
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.
MacTool is offline   Reply With Quote
Old 03-15-2003, 08:21 AM   #10 (permalink)
Travis Dane
Code Monkey
 
Travis Dane's Avatar
 
Join Date: Feb 2003
Location: Netherlands
Posts: 89
Travis Dane is on a distinguished road
Send a message via ICQ to Travis Dane
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.
__________________
OpenGL, DirectX
Travis Dane is offline   Reply With Quote
Old 03-15-2003, 11:04 AM   #11 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
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;
}
Valmont is offline   Reply With Quote
Old 03-15-2003, 11:06 AM   #12 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
Is c++ cool or what?
Valmont is offline   Reply With Quote
Old 03-15-2003, 12:53 PM   #13 (permalink)
MacTool
Registered User
 
MacTool's Avatar
 
Join Date: Mar 2003
Location: Home.
Posts: 5
MacTool is on a distinguished road
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.
MacTool is offline   Reply With Quote
Old 03-15-2003, 01:47 PM   #14 (permalink)
Travis Dane
Code Monkey
 
Travis Dane's Avatar
 
Join Date: Feb 2003
Location: Netherlands
Posts: 89
Travis Dane is on a distinguished road
Send a message via ICQ to Travis Dane
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;
}
__________________
OpenGL, DirectX
Travis Dane is offline   Reply With Quote
Old 03-15-2003, 01:53 PM   #15 (permalink)
Valmont
[code][/code] enforcer
 
Valmont's Avatar
 
Join Date: Mar 2003
Location: Netherlands
Posts: 1,545
Valmont is on a distinguished road
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.
Valmont is offline   Reply With Quote
Reply

Bookmarks

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help for another program Androto Standard C, C++ 54 10-15-2004 07:21 AM
sorting objects arrays by object properties sde Java 28 08-05-2004 05:51 AM
From C to Java HighterDK Java 11 07-13-2004 07:15 PM


All times are GMT -8. The time now is 12:50 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting