Can't populate array with string

I get a:
cannot convert '<brace-enclosed initializer list>' to 'std::string* {aka std::basic_string<char>*}' in assignment

after trying to compile this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

const unsigned short numComponents = 10;

unsigned short prices[numComponents];
string treatments[numComponents];
string appMonday[7], appTuesday[7], appWednesday[7], appThursday[7], appFriday[7];
string nameMonday[7], nameTuesday[7], nameWednesday[7], nameThursday[7], nameFriday[7];

void getPriceList ();
void populateArrays(string toPopulate[]){

    toPopulate = {"F","F","F","F","L","F","F","F"};
}

int main () {
    getPriceList ();
    populateArrays(appMonday);
    populateArrays(appTuesday);
    populateArrays(appWednesday);
    populateArrays(appThursday);
    populateArrays(appFriday);
    populateArrays(nameMonday);
    populateArrays(nameTuesday);
    populateArrays(nameWednesday);
    populateArrays(nameThursday);
    populateArrays(nameFriday);

    return 0;
    }

You cant create the array at one place, and then try to initialize it somewhere else, you're not populating it right now. If you want to populate an array, use a for-loop. Also, if you're only gonna populate your array with F,L or other one letters, its much better to use character array.



Thank you for your help, I am using string because those values will change in future to actual strings.

I did this so:
1
2
3
4
5
6
void populateArrays(string toPopulate[]){

    for (unsigned short i = 0; i <= 7; i++)
        toPopulate[i] = "F";
    toPopulate[4] = "L";
}

and it compiles, but after few seconds i get "program stopped working" and I can't check if my arrays are populated or not.
i <= 7
^

Edit: Change it to i < 7
Edit 2: Consider using Char Array. It takes wayy less bytes and is practically better. F,L are characters.
Last edited on
is that a problem? I changed it to i < 8, but no change
Broski. Your array is [7]. It has 7 spots. From 0-6. Using i < 8 will populate it with 8 (0-7) which you dont have enough space for in your array, making it go out of bounds and it will not work.

I < 7 is the correct way.
that was my blond moment of the day:)
thx
Think your blonde moment of the day was misspelling blonde :p

Happy Coding!
lol
Topic archived. No new replies allowed.