My program works when it is only one word. But how do i get it to work for a whole sentence. This an english to pig latin translator by the way. and i can only use functions from the string library.
The simplest approach would be to use a stringstream to read each word from the input string. However, that seems to be explicitly excluded, so in effect you have to recreate the same functionality for yourself.
Use the getline only version (commented out below) if you want the 'yay' at the end of the sentence or the stringstream version if you want a 'yay' after every word of the sentence
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include <string>
#include <sstream>
usingnamespace std;
int main()
{
string line;
cout<<"Enter a sentence: \n";
getline(cin, line);
// cout<< line + " yay";
stringstream stream(line);
string words;
while (stream >> words)
{
cout<<words + " yay"<<"\n";
}
}
edit: oops, just noticed string only, in that case above solution then