can anyone convert that code into c++ only i mean remove some c language from it and replace it to c++ in order to understand it |
The OP has a point here, I think.
Newbies to C++ often write C code except for the use of cin and cout. I did that too at the start, because I knew C. It took me a while to learn the C++ ways of doing things - which is rather different than C. I am very sure there are lots more things for me to learn - it's a gradual process.
One problem is that people mix up C and C++ thinking - like using an iterator to count chars, when they could just use the string's size function.
The other thing is teachers get their students to write their own sort functions say, because using the STL is way too easy - the student won't learn anything.
Some C++ ideas and comparisons with C (for some of them), not necessarily in order:
Use strings with their built in operators & functionality, instead of array of char with C functions like strcpy;
Use STL containers, like vector or list instead of arrays;
Use other containers like map & set where appropriate, instead of trying to implement these yourself;
Use STL algorithms like find, sort plus many others;
Use iterators to traverse through containers, instead of pointer arithmetic;
Learn function overloading;
Learn to use classes;
Learn Class design - quite involved;
Learn about virtual functions & how to use them;
Learn how to use templates.
There you go, there is a good list for starters!! Probably need a good book from Bjarne Stroustrup who invented C++. There are all kinds of resources on the internet - videos and all.
So for your code, you have char arrays and pointer arithmetic, so change these to strings and make use of the STL string functions.
Look in the reference / documentation section link at the top left of this page - there is a wealth of information there - have a good read, especially the example code.
Don't forget
Google.