Converting Strings to c strings?

Hey everyone,

I'm currently trying to re-create the String Class for, well, class, and I'm running into a few issues. My plan was to edit the strings as c strings, so I could use their array functionality to add/remove or access certain parts. The functions my professor wrote as templates are calling Strings, and so far I haven't been able to convert them to C-Strings as I would like to.

Here's an example of a function I'm trying to make:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
String String::operator + (const String& aString) const
{
	
	char leftString[] = aString;
	char *leftStringPtr;
	int rightLength = GetLength(aString) + 1;
	int leftLength = GetLength(*this);

        // From here on is where I tried everything I could think of, and no dice. Just getting a bunch of "Can't Convert char * to const String" and so forth.
	leftString = aString;
	leftStringPtr = aString;

	leftString[SIZE] = aString;
	leftStringPtr[SIZE] = aString;
	
	leftString = *aString;
	leftStringPtr = *aString;

	&leftString = aString;
	&leftStringPtr = aString;

	
}


If it's in fact impossible to do this conversions (I'd like to go both ways with the conversions, since I have to take in and return Strings), if you (guys) could show me how to alter with sections of strings a different way I'd appreciate that help. If you need the full code (it's around 300 lines, including the header file), let me know and I'll PM it to you so this OP doesn't get really long, unless there's an attachment system on here I haven't noticed yet.

Many thanks!


EDIT: After many hours, and a few phone calls, here are the lines that work:

1
2
3
4
5
6
7
8
9
10
11
char * leftStringPtr = "";
	char * rightStringPtr = "";
	
	leftStringPtr = Text;
	rightStringPtr = aString.GetText();

	int rightLength = GetLength(aString) + 1;
	int leftLength = GetLength(Text);
	int totalLength = leftLength + rightLength;

	char * fullString = new char[totalLength];


Last edited on
Topic archived. No new replies allowed.