Mar 17, 2004 #1 Jerrie85 IS-IT--Management Joined Feb 10, 2004 Messages 29 Location CA how would i convert a char array to string? e.g string temp; char chararray[100]; temp should have chararray's contents from 0 to 500 how would you do this?
how would i convert a char array to string? e.g string temp; char chararray[100]; temp should have chararray's contents from 0 to 500 how would you do this?
Mar 17, 2004 #2 uolj Programmer Joined Jul 2, 2003 Messages 529 Location GB If the char array is null terminated, you can just assign it: Code: string temp = chararray; // or string two; two = chararray; If the array is not null terminated, or you only want to assign the first 50 characters, you can do like this: Code: string temp(chararray, chararray + 50); string two; two.assign(chararray, chararray + 50); Upvote 0 Downvote
If the char array is null terminated, you can just assign it: Code: string temp = chararray; // or string two; two = chararray; If the array is not null terminated, or you only want to assign the first 50 characters, you can do like this: Code: string temp(chararray, chararray + 50); string two; two.assign(chararray, chararray + 50);
Mar 18, 2004 Thread starter #3 Jerrie85 IS-IT--Management Joined Feb 10, 2004 Messages 29 Location CA how would you assign it to the string from the nth position to the ith position, instead of from 0 to n? so for a char[1000], i wanna assign to string from position 3 - 10? Upvote 0 Downvote
how would you assign it to the string from the nth position to the ith position, instead of from 0 to n? so for a char[1000], i wanna assign to string from position 3 - 10?
Mar 18, 2004 #4 rchandr3 Programmer Joined Jun 16, 2003 Messages 244 Location US Convert that to a CString and after that you can do whatever manipulations you want with that... Cheers, Ravi Upvote 0 Downvote
Convert that to a CString and after that you can do whatever manipulations you want with that... Cheers, Ravi
Mar 18, 2004 #5 uolj Programmer Joined Jul 2, 2003 Messages 529 Location GB Jerrie85 said: how would you assign it to the string from the nth position to the ith position, instead of from 0 to n? so for a char[1000], i wanna assign to string from position 3 - 10? Click to expand... Ahh, c'mon, you can figure it out! ... Ok, here you go: Code: char chararray[1000]; // ... load chararray string temp(chararray + 3, chararray + 10); string two; two.assign(chararray + 3, chararray + 10); Upvote 0 Downvote
Jerrie85 said: how would you assign it to the string from the nth position to the ith position, instead of from 0 to n? so for a char[1000], i wanna assign to string from position 3 - 10? Click to expand... Ahh, c'mon, you can figure it out! ... Ok, here you go: Code: char chararray[1000]; // ... load chararray string temp(chararray + 3, chararray + 10); string two; two.assign(chararray + 3, chararray + 10);