//I can't see any issues with the way I was using to define String back as String simstring backwards, but I get an on Output Error, saying:
//index out of range: 0 string:
//Note: This program is not completed (obviously). I still have to account for multiple word palindromes, etc., but I was trying to get it done properly with single words before I moved on.
//I definitely need to create a new string which is equal to the original backwards. It just won't let me
/* Project Palindrome
by Jacob Wright 2-21-13 */
#include <iostream.h>
#include <lvp\string.h>
#include <stdlib.h>
//________________________________
void assimilate(String simstring); //Removes capitalization differences and punctiation from simstring
//________________________________
void compare(String oristring, String newstring){} //Tests if both strings are the same, and outputs
//________________________________
int main()
{
String input;
cout << "\n\n\n\n\n\t\t Input a String to be tested: ";
cin >> input;
cout << flush;
system("cls");
cout << "\n\n\n\n\n";
assimilate(input);
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\t ";
return(0);
}
//_________________________________
void assimilate(String simstring)
{
for (int c=0; c<simstring.length(); c++)
{
if ((simstring[c]>='a') && (simstring[c]<='z'))
simstring[c]=simstring[c]-'a'+'A';
}
cout << "\t\t Original String: " << simstring;
cout << "\n\n\n\t\t Backwards String: ";
String back;
int z=0;
for (int C=simstring.length()-1; C>=0; C--)
{
back[z]=simstring[C];
z++;
}
cout << "\n\n" << back;
}
Also, another option( to add to Cire's post, in your duplicate thread ).
You can re-size the string, to the size of the string you wish to copy in to it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
std::string input;
std::cout << "Please enter some text: ";
std::getline( std::cin, input, '\n' );
std::string copy;
// Change the length of copy and fill with '+'.
copy.resize( input.length(), '+' );
// The above is for a visual reference.
// You can just pass .resize() the value you wish
// to resize too, as the statement below:
/* copy.resize( input.length() ); */
std::cout << "text: " << input << '\n';
std::cout << "copy: " << copy << '\n';
output:
Please enter some text: hi there
text: hi there
copy: ++++++++