Need help with fixing a warning, warning listed below

Hey, I Have a problem with my code. Whenever I compile & run it I get a warning message saying:
[Warning]extended initializer lists only available with -std=c++11 or -std=gnu+11 [enabled by default]

Oh and about the program itself, it's supposed to change the first letter in the persons name with Z, so for example Jenny would be Zenny.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  #include <iostream>

using namespace std;
int main(int argc, char** argv) {
	
	string c;
	
	cout << "Type in your name: ";
	cin >> c;
	
	string {0} = 'Z';
	
	cout << "No your name is: " << c;
	

	return 0;
}
line 11, c[0] = 'Z';
string {0} = 'Z';
What do you think it is doing?
Answer is: nothing useful.
I suppose you are creating temporary string and assign it value "z" which is instantly destroyed.

You probably want c[0] = 'Z' here.

As for warning, turn on C++11 support. Do it anyway because not using C++11 features is not using C++ in full power.
Oh wow, thank you. I dont know how I messed up so much by putting string instead of c. My bad, stupid thread. I've literally been staring at his for ages and the second I saw your reply I was like "SH!T I'm dumb."
<pedantic>
The line 11 should probably contain
1
2
3
if ( ! c.empty() ) {
  c[0] = 'Z';
}

Rationale:
Line 9 can make the c an empty string and attempt to modify c[c.size()] is undefined behaviour.
Line 9 can make the c an empty string
Only with some non-standard actions on user side (manualy send end-of-stream), or if you redirect empty stream to program.
Topic archived. No new replies allowed.