Skip to main content
gamedev.net
🔒 Locked

c++: Compiling Error

Started by ceribik Sep 8, 2007 at 12:02 AM 1 replies 550+ views
Original Post
ceribik
ceribik
Hey, I'm trying to make a program that reverses the string that the user inputs in, but I'm having some problems compiling and I can't see the typo that I've made.
#include <iostream>
#include <string>

using namespace std;

void reverseString(string& string);

int main (int argc, char * const argv[])
{
    string s;
    cout << "Enter a string: ";
    getline(cin, s);
    
    reverseString(s);
    cout << "Reversed string = " << s;
    
    return 0;
}

void reverseString(string& string)
{
     int strLength;
     string rvrString; // Line where I'm getting the error
     
     strLength = string.length();
     
     for (int j = 0, i = strLength - 1; i <= 0; i--, i++)
     {
     } 
}
Quote:
expected ';' before 'rvrString
As far as i can see, I haven't left out any semicolons, so why am I getting this error? Any help would be appreciated. Thanks.
Shlaklava
Shlaklava
Your argument for the reverse string function is like this:

reverseString(string& string);

There is one problem. It should not have the word string as a parameter name. Use something different. Example:

reverseString(string& strrev);

That would probably work. Make sure to not have class names as argument names.
ceribik
ceribik
Ah ok, that makes sense. I'll make sure not to do that again - and it works now.

Thanks :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.