• Register
Welcome to Kodlogs, programming questions and answer website.
+1 vote
6 views

Problem :

I am trying to enter numbers for my array br_el[6], and also I want it to show me for what object I am entering my number! So when I want to compile it gives me the below error:

"[Error] cannot pass objects of non-trivially-copyable type 'std::string {aka class std::basic_string}' through '...'"

 I have already tried to declare the string qr_naziv[6]; but my string didn't even bold so it didn't work for me, so looking for the solution on my error ?

by (7.5k points)  
reopened by

1 Answer

0 votes

Solution :

I had also faced the similar issue in the recent past. I did lot of research on it and found the solution on it. This is the very common problem with the people getting started.

I must tell you that C functions are not acquainted with the C++ structures. You should do as the below:

​
...
for(j = 0; j < 6;j++) {
    printf("Input your number for %s =", qr_naziv[j].c_str());
    scanf("%d", &br_el[j]);
}
...

​

Please notice the call to your method c_str() on a each std::string qr_naziv[j], which returns the const char * to the null-terminated character array with the data equivalent to those stored in a string -- a C-like string.

If you follow the solution then your issue will be resolved.

by (33.3k points)  
edited by
...