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*'

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

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.