Friday, November 30, 2007

String manipulations.

I was and still am bad at string manipulation .I have known a few functions from Google, the God which are very useful in coding (when the program involves strings).
1) To replace a substring of a string with new string - string replace.
2) To insert a new substring in a string- string.insert(position where u want to insert, substring);
3) when the file You want to read is a variable say name and it needs to be replaced with its content when you want to use it -- string.c_str().
Example: fread(name.c_str(),"rb") where name variable has your target file name.
4) To get a char* from const char *.
Define a variable with char * say target.
The available string ( which is const char*) is say source.
strcpy(target,source) would do the job.( ok i struggled to get this job done, might have been easy for others).

2 comments:

Harishankaran said...

Hmmm, nice post. :-)
Would have been lots more helpful if you had given examples for each function, like you have mentioned for fread.

lavanya said...

yup will do that from next time :)