With the way I have it set up now I am getting an invalid conversion from char to string, I've changed everything to cstring arrays and get an invalid conversion from char to char error message. Now that's funny!
So I may be using the wrong type for the pointers, or the wrong method of passing the string to the function I'm not sure.
If you look down the code to the ptr1 and ptr2 pointers I am attempting to create, I want to switch out the start and end int variables with the pointers of ptr1 and ptr2. and do the exact same string reversal.
I would appreciate any and all suggestions. Also you can ignore the return temp line, I'm not using it right now I know but I'm not sure if I'm going to print the final line in main or the sub function yet so I left it in there for now.
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
string switchit(string& s);
int main()
{
string stuff1 = "this is stuff";
string stuff2 = "racecar";
string stuff3 = "this is a test dude";
string stuff4 = "1234567";
cout << "\nThis is original string 1: \n";
cout << stuff1 << "\n\n";
switchit(stuff1);
cout << "\nThis is original string 2: \n";
cout << stuff2 << "\n\n";
switchit(stuff2);
cout << "\nThis is original string 3: \n";
cout << stuff3 << "\n\n";
switchit(stuff3);
cout << "\nThis is original string 4: \n";
cout << stuff4 << "\n\n";
switchit(stuff4);
system("PAUSE");
return EXIT_SUCCESS;
}
string switchit(string& s)
{
// char *ptr1;
// int *ptr1; //these methods all had errors also
int start = 0;
int end = s.length();
string *ptr1;
string *ptr2;
ptr1 = s[0]; //errors out on compile invalid char/string conversion
ptr2 = s[end];//errors out on compile invalid char/string conversion
string temp(s);
while(start < end)
//while ptr1<ptr2)
{
end--; //want to switch out for ptr1
//ptr2--;
swap(temp[start],temp[end]);
//swap(ptr1,ptr2); //this is what I need to do, swap the pointers
start++;
//ptr1++;
}
cout << "\nThis is the modified string: \n";
cout << temp << "\n\n";
return temp;
}
This post has been edited by badjava: 01 December 2008 - 12:21 PM

New Topic/Question
Reply




MultiQuote








|