0
What happened?
Note that reverse(sentence) is not the problem. int main() { cout << "enter a sentence" << endl; char* cin << sentence; reverse(sentence); }
7 Antworten
+ 1
make this
int main()
{
cout << "enter a sentence" << endl;
char sentence;
cin >> sentence;
reverse(sentence);
}
+ 1
compile error
+ 1
bayram akdemir is actually correct. everyone commenting has missed the obvious mistake except him.
cin requires >>
cout requires <<
i can not figure out what you were trying to do with char* cin...
0
What happens when you run your code?
0
Output?
0
I did. First off I don't have your code for the reverse() function.
Second, when you use a char, it only stores one character i.e. 'A'.
To store a string of characters use string. I think that's the problem you're having.
EDIT: Compiler error: note: Candidate (reverse) expects 2 arguments, 1 provided. So reverse is a part of stl_algo.h
If you are going to use features provided by stl, make sure you first know how to use them/ what arguments they require.
- 1
Try this:
int main()
{
string sentence;
cout<<"Enter a sentence.\n";
cin<<sentence;
reverse(sentence.begin(), sentence.end());
cout<<sentence<<'\n';
return 0;
}