• Register
1 vote
158 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 ?

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.

36.1k points
edited by

Related questions

1 vote
1 answer 14 views
14 views
Problem: Hello all, I am struggling to solve a problem for the last thirty minutes using the c++ programing language. I was thinking of writing a program that will read the defined string and iterate through it and print all the words separately. Suppose I initialize a string with ... it very much How do you it or suggest me an easy way to do that. I look forward. Thanks for your kind assistance.
asked Jun 15 adamSw 11.3k points
2 votes
1 answer 10 views
10 views
Problem: Hello all, I am a student of C++ programming. I am wondering if there's an abbreviation or a more elegant way of getting the last character of a string. Let&rsquo;s assume, the given string is &ldquo;I am a String&rdquo; then the output should be ... ; I&rsquo;ve almost 30 minutes for the problem and couldn&rsquo;t figure out any legit solution. I hope you people would be helpful. Thanks.
asked Apr 18 Gavin 15.2k points
0 votes
1 answer 2 views
2 views
Is there a way to find how many values an array has? Detecting whether or not I have reached the end of an array would also work.
asked 4 days ago game 1.5k points
1 vote
1 answer 16 views
16 views
Problem : I am new to C programming. I have recently started working on exercise. Please find below my code for your reference: int mydistinct(int a[], int n) { int i, k, j, count=0; int max = a[0]; for (i = 1; i < n; i++) { if (max < a[i]) { ... . In this case my code will only try to count 8,7,6,5 and it will return only four unique numbers. So I am looking for proper guidance in C programming.
asked May 19 Martin K 6.6k points
1 vote
1 answer 10 views
10 views
Problem : I am very new to programming. I have recently started learning C programming. Please find below the one way of initializing the array: I have one doubt about my above program : Which of the following is not a correct way to initialize an array? int n[ 5 ] = { 0, 7, 0, 3, 8, 2 }; int m[3] = ... [1] 15};     printf("m[0] = %d  m[1] = %d   m[2] = %d\n", m[0], m[1], m[2]);     return 0; }
asked Apr 27 stewart 4k points