Using arrays in string

How to fix this ? I am encounter with string and integer.
The code line 10 : sum += week[x] .. not match for operator += because sum(int) and week(string).

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

int main()
{
    string week[7] = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};
    int sum =0;

	for (int x =0 ; x <7; x++){
        sum += week[x]; // Error, not match for operator +=
        cout << sum << endl;

	}


}
Last edited on
From your code, I can only understand that you are trying to sum up the ASCII values of each letter in your string array. Is that right?
Nope, I just want to display my string array in command prompt.
Example:
Monday
Tuesday
Wednesday
...
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
using namespace std;

int main()
{
    string week[7] = {"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"};

	for (int x =0 ; x <7; x++){
        cout << week[x] << endl;
	}
}


No need for "sum";
Topic archived. No new replies allowed.