+ 6

Please I keep getting some error message from this code which I don't know how to fix it

// C++ program to print all n-digit numbers whose digits // are strictly increasing from left to right #include <bits/stdc++.h> using namespace std; // Function to print all n-digit numbers whose digits // are strictly increasing from left to right. // out --> Stores current output number as string // start --> Current starting digit to be considered void findStrictlyIncreasingNum(int start, string out, int n) { // If number becomes N-digit, print it if (n == 0) { cout << out << " "; return; } // start from (prev digit + 1) till 9 for (int i = start; i <= 9; i++) { // append current digit to number string str = out + to_string(i); // recurse for next digit findStrictlyIncreasingNum(i + 1, str, n - 1); } } // Driver code int main() { int n = 3; findStrictlyIncreasingNum(0, "", n); return 0; }

13th Nov 2021, 9:39 AM
alexpetra54
16 odpowiedzi
+ 2
So I am trying to make n= 7 but it not giving me the exact result
13th Nov 2021, 3:54 PM
alexpetra54
+ 2
Did you forget to #include <iostream>? There is also a string header which may help. Cant test at the moment away from my computer. Some things change for different versions of c++, so just check your version that your compiler is using and compare with SoloLearn's c++ complier choice and version.
14th Nov 2021, 11:12 PM
Adam McGregor
+ 1
Really! Maybe it's my compiler... I use dev++ IDE
13th Nov 2021, 11:36 AM
alexpetra54
+ 1
Can you describe what error message was given by that IDE?
13th Nov 2021, 11:49 AM
Ipang
+ 1
Invalid conversion from 'int' to 'conts char*' [-fpermissive]
13th Nov 2021, 11:57 AM
alexpetra54
+ 1
Did it say the line number?
13th Nov 2021, 11:58 AM
Ipang
0
Line 18 col 43
13th Nov 2021, 11:59 AM
alexpetra54
0
I think it from that findStrictlyIncreasingNum(i+1, str, n-1);
13th Nov 2021, 12:01 PM
alexpetra54
0
Probably ... but to_string() returns a std::string. The message mentioned `int` to `char*` And that line (as per the copy of your code) isn't located at line 18 either ...
13th Nov 2021, 12:06 PM
Ipang
0
Can you help with the fix
13th Nov 2021, 12:08 PM
alexpetra54
0
The thing is, I don't get that warning as I tested run the code. Then I have no idea where to look for something possibly bug ... I can remove my responses here to return your question into "Unanswered" state. Hopefully someone more knowledgeable comes in ...
13th Nov 2021, 12:11 PM
Ipang
0
You Don't have to do that... What ide or environment do you use to run the code?
13th Nov 2021, 12:16 PM
alexpetra54
0
Alex, Sorry for delay, had to run. Anyways, the code was tested in SoloLearn and rextester. Both of which gave output but no error, nor warning ...
13th Nov 2021, 3:31 PM
Ipang
0
Ok... Can you please edit the code , and make n =8
13th Nov 2021, 3:52 PM
alexpetra54
- 1
I copied & pasted the code into a C++ code bit and ran it. I see output, no error message ...
13th Nov 2021, 10:59 AM
Ipang
- 1
I have run it in sololearn and it worked
13th Nov 2021, 3:53 PM
alexpetra54