Hello! Im having trouble with reversing string in this program:
#include <iostream>
#include <string>
using namespace std;
int numChars(string besedilo[])
{
int znaki=0;
int vrstica=0;
for(int a=0;a<10;a++)
{
vrstica=besedilo[a].length();
znaki=znaki+vrstica;
}
return znaki;
}
int numWords(string besedilo[])
{
int besede=0;
string vrsta;
for(int a=0;a<1;a++)
{
vrsta=besedilo[a];
for(int b=0;b<besedilo[a].length();b++)
{
if(vrsta[b]==' ' || vrsta[b]=='\n')
{
besede++;
}
}
besede++;
}
return besede;
}
int reverseString(string stavek)
{
std::string str = stavek;
std::string rstr = str;
std::reverse(rstr.begin(), rstr.end());
std::cout << rstr << std::endl;
}
int main()
{
string vrstica[10];
string ime;
int meni;
cout<<"Vnesi besedilo: "<<endl<<"---------------"<<endl<<endl;
for(int a=0;a<1;a++)
{
getline(cin,vrstica[a]);
}
cout<<endl<<"-----------------------"<<endl;
do
{
cout<<"+++++++++++++++++++++++++++++++++++++++++++++++++"<<endl;
cout<<" MENU +"<<endl;
cout<<"1. Izpise stevilo vnesenih znakov +"<<endl;
cout<<"2. Izpise stevilo vnesenih besed +"<<endl;
cout<<"3. Obrne niz +"<<endl;
cout<<"0. Izhod +"<<endl;
cout<<"+++++++++++++++++++++++++++++++++++++++++++++++++"<<endl<<endl;
cin>>meni;
if(meni==1)
{
cout<<"Vneseno je bilo "<<numChars(vrstica)<<" znakov!"<<endl;
}
if(meni==2)
{
cout<<endl<<"Vneseno je bilo "<<numWords(vrstica)<<" besed!"<<endl;
}
if(meni==3)
{
cout<<reverseString(vrstica);
}
}
while(meni!=0);
return 0;
}
Can anyone help me with this problem? Thanks.