hi guys just a query basically I have created the following program, which takes a word then shows the position of a certain character. Now what I need to do is then print out each characters position in the array: so for example
T E S T
0 1 2 3.. etc
I just need some help on how to implement this into my code, I'm assuming it would be by storing the values then using pointers??
Many Thanks
#include <string>
#include <iostream> // allows program to output data to the screen
#include <cstring>
using std::string;
using std::strlen;
using std::cout; // program uses ‘cout’
using std::cin; // program uses ‘cin’
using std::endl; // program uses ‘endl’
int main()
{
string s1;
int location;
int locationL;
const int MAXINPUT = 128;
char inputBuffer[MAXINPUT];
const int FIRSTINPUT = 128;
char findFirst[FIRSTINPUT];
cout << "Please input a string: " <<endl;
cin.getline(inputBuffer,MAXINPUT);
//void getLength()
{
cout << "You input: " <<endl;
cout << inputBuffer <<endl;
cout << "The length of the string is: " << strlen(inputBuffer) <<endl;
string str1( inputBuffer );
cout << "Please enter a character to search for: ";
cin >> s1;
int location = str1.find(s1);
cout << "First occurrence of '" << s1 << "' at: " << location+1 << endl;
int locationL = str1.find_last_not_of(s1);
cout << "Last occurrence of '" << s1 << "' at: " << locationL+2 << endl;
cout << "Reverse string: ";
for(int i = str1.length()-1; i >= 0; i--)
{
cout << str1 [i] ;
} cout << endl;
return 0;
}
}