Skip to main content
GameDev.net gamedev.net
🔒 Locked

String Class

Started by LiquidNRG Dec 26, 2001 at 6:35 PM 2 replies 400+ views
Original Post
LiquidNRG
LiquidNRG
In my engine which I am developing I am using the new style C++ but as yet in the String class which I have done I have not been able to find a way round the following problems. The class has only member variables which are an int for the length and a char* for the data. 1. I want a constructor which takes a char* as an argument but i at the moment I need to use strlen so I can get the length. 2. I need a function to put int''s into the string and at the moment I have to use sprintf and this returns a length as well as having a char* to copy the data from into the class
DrPizza
DrPizza
I''m not entirely sure what the question you''re asking is (both methods you''re using will work, after all), but I''m not sure why you''re not using std::string and std::stringstream.

char a[99999],*p=a;int main(int c,char**V){char*v=c>0?1[V]:(char*)V;if(c>=0)for(;*v&&93!=*v;){62==*v&&++p||60==*v&&--p||43==*v&&++*p||45==*v&&--*p||44==*v&&(*p=getchar())||46==*v&&putchar(*p)||91==*v&&(*p&&main(0,(char**)(--v+2))||(v=(char*)main(-1,(char**)++v)-1));++v;}else for(c=1;c;c+=(91==*v)-(93==*v),++v);return(int)v;} /*** drpizza@battleaxe.net ***/
krez
krez
quote:
Original post by YourOtherLeft
1. I want a constructor which takes a char* as an argument but i at the moment I need to use strlen so I can get the length.


what''s wrong with strlen? well, anyways, you can go through the char* with a for loop, keep count of characters, and stop when you hit a 0 (''/0'').

--- krez (krezisback@aol.com)
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.