Function to write string 3 times
Hi. I'm trying to write a function that will write a string 3 times to the standard output.
This is how far I've got:
// a function to write a string 3 times to standard output
#include <iostream>
#include <string>
using std::cout; using std::endl;
using std::cin; using std::string;
string name3times(string);
int main()
{
cout << "Type your first name: ";
string name;
cin >> name;
cout << "Hello, " << name3times(name) << endl;
return 0;
}
string name3times(string name)
{
return
cout << name + "!" << endl;
cout << name + "!" << endl;
cout << name + "!" << endl;
}
I keep getting the following error message from the compiler:
ex5-2b.cc: In function `class string name3times(basic_string<char,string_char_traits<ch ar>,__default_alloc_template<false,0> >)':
ex5-2b.cc:24: conversion from `ostream' to non-scalar type `string' requested
Thanks for any help in advance!
Giggs