String Class

Started by
2 comments, last by LiquidNRG 22 years, 3 months ago
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
Advertisement
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 ***/
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])
use the the standard string class, it has everything you need and more. Don''t bother making your own, unless you would rather work on a string class than a game.

This topic is closed to new replies.

Advertisement