Visit the Ironworks Gaming Website Email the Webmaster Graphics Library Rules and Regulations Help Support Ironworks Forum with a Donation to Keep us Online - We rely totally on Donations from members Donation goal Meter

Ironworks Gaming Radio

Ironworks Gaming Forum

Go Back   Ironworks Gaming Forum > Ironworks Gaming Forums > General Discussion > General Conversation Archives (11/2000 - 01/2005)
FAQ Calendar Arcade Today's Posts Search

 
 
Thread Tools Search this Thread
Old 06-24-2004, 08:02 AM   #1
LennonCook
Jack Burton
 

Join Date: November 10, 2001
Location: Bathurst & Orange, in constant flux
Age: 37
Posts: 5,452
Basically, I have a very large program which is *almost* compiling: my only problems are with a line that looks like:
code:
std::string input = temp;
[/QUOTE]Where temp is a char* . My compiler (Borland 5) tells me "Cannot convert char* to std::string" . I've tried changing the code to be:

code:
std::string input(temp);
[/QUOTE]
But Borland tells me "No match for string::string(char *)".
But when I try this silly little block of code that I found elsewhere (in response to another problem related to the same classes), it compiles without so much as even a warning.
code:
#include <cstring>
#include <string>
#include <iostream>
using namespace std;

int main(){
char *t;
char u[50];
char *v;
string w;
string s;

t = "this string is t, it is a very long string. much longer than 30 chars.\n";
strcpy(u, "this is u, it is also a fairly long string.\n");
v = strdup(u);
v[8] = 'v';
w = "and this is string w, it's not a char array like the rest.\n";

s = t;
s += u;
s += v;
s += w;

delete v;
cout << s;
}
[/QUOTE]
So, is there any rhyme or reason to Borland's complaining? And, more importantly, is there any way to fix it?
LennonCook is offline  
Old 06-24-2004, 10:44 AM   #2
philip
Galvatron
 

Join Date: June 24, 2002
Location: aa
Posts: 2,101
I don't have any c++ experience (not counting nwscript [img]smile.gif[/img] ) but what I often do when I get an error I don't get is use google with the exact code of the error, except for my own constants or declarations.

When I did that with your code I got to this site, under the 'C++ has scary error messages' it looks like a similar error to the one you have. Also the description of the error is good looking at the error message you've got.

BTW and this is purely a guess at it cause as I said I don't know much about c++ but those 2 declarations look so similar I doubt they do much different things. Again I don't know about c++ but other languages have convert functions maybe you could try those (if they're in c++ of course), cause right now it looks like you're trying to declare a char* as string (also from the msg) which IMHO doesn't look very if that's possible so easy.

Why I think the other piece of code works. It looks like that piece is adding characters to a string, instead of immediately equalling a string to a char*?
philip is offline  
Old 06-24-2004, 11:30 AM   #3
Vaskez
Takhisis Follower
 

Join Date: April 30, 2001
Location: szép Magyarország (well not right now)
Posts: 5,089
Firstly, I don't think you don't need std:: in front of string if you declare "using namespace std;" at the top

code:
string input( temp );
[/QUOTE]seems like it should work, but according to my reference you need a const char* not a char* as the input. So you could try casting temp to a const char* first, or copying its value to an already declared const char*.

You could also try

code:
string input;
input = temp;
[/QUOTE]Yes, I find that it does make a difference if you declare the variable on the same line or not.

Let me know if it doesn't work, I might have some suggestions, including checking out this site:

http://www.cppreference.com/cppstrin...l#Constructors
__________________
Too set in his ways to ever relate
If he could set that aside, there'd be heaven to pay
But weathered and aged, time swept him to grave
Love conquers all? Damn, I'd say that area's gray
Vaskez is offline  
Old 06-24-2004, 09:07 PM   #4
LennonCook
Jack Burton
 

Join Date: November 10, 2001
Location: Bathurst & Orange, in constant flux
Age: 37
Posts: 5,452
Time for me to slap myself silly. I've been using a string class which I coded, which publically inherits from std::string . I needed to provide my own constructors, and the assignment operator is virtual. Fixed up those two problems by adding few lines to my class, and it now compiles.

I now need to test this thing very quickly because it's due on Monday. It's a CGI application, and so I need a webserver which can be set up to run a binary file server-side. Meaning, I either need someone who has such a webserver, or I need to figure out how to configure Apache... and then there's the user manual...
LennonCook is offline  
 


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

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 On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
gesen string pschub Baldurs Gate II: Shadows of Amn & Throne of Bhaal 1 12-16-2002 03:29 PM
Gesen string kods2001 Baldurs Gate II: Shadows of Amn & Throne of Bhaal 2 03-28-2002 08:23 AM
Gehsen's Bow String...HELP??? mastodonian Baldurs Gate II Archives 2 07-24-2001 04:41 PM
Bow String? insomniacau Baldurs Gate II Archives 5 06-15-2001 07:53 AM
Bow to go with the string? Sherpa Doug Baldurs Gate II Archives 7 03-15-2001 04:39 PM


All times are GMT -4. The time now is 05:14 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
©2024 Ironworks Gaming & ©2024 The Great Escape Studios TM - All Rights Reserved