hello i have a code and i have to know the size of the string for my loop.
i have searched the faq ive seen something with an inline function and a template but ican't compile it. i think that is because it has to be const but when its const i cant set a value to the string normal.
can someone tell me how to fix this or how i can reverse my string and how i can make all the r to l ?
here is the code:
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
//----------------------------------------------
//i have this part from the FAQ
template <typename T, size_t N>
inline
size_t SizeOfArray( const T (&)[ N ] ) // i have tried to remove the const in here but that doesnt work to
{
return N;
}
//-----------------------------------------------
int main () {
int i;
string normal,reversed,R_To_L;
getline(cin,normal);
for(i=SizeOfArray(normal);i>0;i--) {
reversed[i-1]=normal[SizeOfArray(normal)-i];
if(normal[i-1]='r')
{ R_To_L[i-1]='l';}
else
{R_To_L[i-1]=normal[i-1];}}
cout<<normal<<endl<<reversed<<endl<<RToL<<endl;
system("pause");
return 0;
}
This doesn't even come close...you have no strings in here.
Also, this problem would be easier if you looked at a string for what it is...a container, whose elements can be played with at will, as long as you know their index (hint, hint).
And last, but not least, you might want to look in on stringstreams. Although not strictly necessary, they are useful.
Don't change your code after the fact. I read your code before, they were NOT strings, they were char. And yes, i is the index, but you have to know how to use it in the context of containers to rearrange the letters inside of the container whose type is string.