0

Hi

I have a syntax problem which I dont know how to correct. The below line of code is meant to check whether the 1st character of a string is a vowel, if not, then the 1st character is sent to the end of the string & then the program checks whether the next character is a vowel & so on.

string a = "There";

while ( !isvowel(a[0]) )
	{
		a.insert(a.length(), a[0] ); // error line 
		a.erase(a[0]);

	}

The error message is

initializing argument 1 of `std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const _CharT*, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = std::allocator<char>]'
- invalid conversion from `char' to `const char*'

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by wildgoose
0

It looks like the parameter needs a char* not a char . IOW you need to pass the string, not the character.

0

You aren't copying a string, merely a single character, so use the following...

a.insert(a.length(), 1, a[0] ); // error line

...to append the character!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.