I'm writing a "pig latin" program; read input from the users (first name and last name,) make the input lowercase and change the name depending upon what was in the name. If the first letter (of both the first and last name) was a vowel, we're supposed to add "way" to the end of it.
If the first letter was a consonant, we were to take the first letter, move it to the end of the string and add "ay" to the end of it.
My code has been giving me errors when trying to add text to the end of the string. It says it can't convert the string to a character, and I'm not exactly sure what that means. It also says I can't use the output operand << for strings, even though I've used it before.
The errors occur with "strcpy" and the final code where I output the names.
37: error: cannot convert
'std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >'
to'char*'
for argument'1'
to'char* strcpy(char*, const char*)'
47: error: cannot convert
'std::vector<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >'
to'char*'
for argument'1'
to'char* strcpy(char*, const char*)'
54: error: no match for
'operator<<'
in'std::cout << first'
I just need some help fixing the errors and seeing where I went wrong. The full code is included.
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
using namespace std;
int main()
{
int q, s;
char shea[] = "way";
char gavin_stop_looking_at_ponies[] = "ay";
vector <string> first;
vector <string> last;
cout << "Please enter your first name." << endl;
for (int i = 0; i < first.size(); i++)
{
getline (cin, first[i]);
string nfirst = first[i];
while (nfirst[q])
{
nfirst[q] = tolower(nfirst[q]);
}
first[i] = nfirst;
}
cout << "Please enter your last name." << endl;
for (int j = 0; j < last.size(); j++)
{
getline (cin, last[j]);
string nlast = last[j];
while (nlast[s])
{
nlast[s] = tolower(nlast[s]);
}
last[j] = nlast;
}
if ( (first[0] == "a") ||( first [0] == "e") || (first [0] == "i") || (first [0] == "o") || (first [0] == "u"))
{
strcpy (first, "way");
}
else
{
first[first.size()] = first[0] + "ay";
}
if ( (last[0] == "a") ||( last [0] == "e") || (last [0] == "i") || (last [0] == "o") || (last [0] == "u"))
{
strcpy (last, "way");
}
else
{
last[last.size()] = last[0] + "ay";
}
cout << first << last << endl;
return 0;
}