void slova(string datoteka){
    ifstream coban;
    coban.open(datoteka.c_str());
    string polje[200];
    string linija;
    int brojac=0;
    while(!coban.eof()){
    getline(coban,linija);
    polje[brojac]=linija;
    brojac++;
}   

string rec=polje[1];
int brojac2=0;
for(int i=0;i<rec.length();i++){brojac2++;}
cout<<brojac2<<endl;
        
   if(rec[0]==rec[brojac2]){cout<<"same letters"<<endl;}
   else{cout<<"letters are not same"<<endl;}
}

This is my code, it should test if 1st and last letter in string are same, but i can't get it to work.

Please somebody help me, i would really appreciate it.

Thank you in advance.

Member Avatar for iamthwee

maybe rec[0] == rec[rec.length()-1]

maybe rec[0] == rec[rec.length()-1]

Thank you man, you are my hero, its working perfrect. :))

Have a nice day!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.