Please embedded the solution into program so that it compiles. Thank you, #include //To do user inputs and outputs #include //To use vectors #include //To use special string functions #include //To use back_inserter using namespace std;
Need help fixing C++ program. Please help me convert a string vector unto a character vector.
Please embedded the solution into program so that it compiles. Thank you,
#include <iostream> //To do user inputs and outputs
#include <vector> //To use
#include <string> //To use special string functions
#include <iterator> //To use back_inserter
using namespace std;
template <class T>
void output(vector<T> values) //Function needed to print vector
{
for (int index = 0; index < values.size(); ++index) //Cycle through entire vector # of elements found
{
cout << values[index] << " "; //Print value
}
cout << endl;
}
template <class T> void
rotateLeft(vector<T>& values)
{
for (int index = 0; index < values.size(); ++index) //Cycle through entire vector # of elements found
{
output(values); //Print vector to user
T tempValue = values[0]; //Start vector from the beggining
for (int move = 0; move < values.size() - 1; ++move) //Cycle through entire vector element to be modified
{
values[move] = values[move + 1]; //Move value ahead once
}
values[values.size() - 1] = tempValue; //Store the value of the modified location
}
}
bool validateInputDigits(string input) //Validate if input is numeric or string
{
for (int i = 0; i < input.length(); i++) //Check through each character in the input
{
if (isalpha(input[i]) == false && (input[i] != '.')) //Check for alphabetical values
{
cout << "\nUser did not enter the a alphabetical character. Please re-start program.\n";
exit(0);
}
}
return true;
}
int main()
{
vector<char> charVectorInput = {}; //Vector for user entered characters
const int SIZE = 4; //Size of user entered input vectors
vector<string>input(SIZE); //Vector to check all user inputs
//Section for character inputs
cout << "\nEnter four character values.\n"; //Accept 4 user entered values
for (int index = 0; index < SIZE; index++)
{
cout << "Please enter input # " << (index + 1) << ": ";
cin >> input[index]; //Accept input from user
validateInputDigits(input[index]); //Check if input is string or numeric
//*****Need help here. I can not copy a string vector to a character vector.
//I need to convert from string data type to char data type,
//and keep it as a vector to meet the assingment requirements
charVectorInput.push_back(input[index]); //Convert and assing value
}
cout << endl;
rotateLeft(charVectorInput);
cout << endl;
return 0;
}
Step by step
Solved in 3 steps with 3 images