import java.util.*;
class occult {
public static void main(String[] args){
int n = 2;
for (int i = 0; ; i++){
if(Integer.toString(i).contains("666")){
if ( n == 1 )
System.out.println(i);
n -= 1;
}
}
}
}
I have written the above java code into c++ . i wanted to know is this the correct way to translate into c++.
is there any better way to achieve in c++.
#include<iostream>
#include <sstream>
using namespace std;
string toString(int n){
ostringstream oss;
oss << n;
return oss.str();
}
int main()
{
int n = 2;
string occult("666");
for (int i = 0; ; i++)
{
if(toString(i).find(occult) != string::npos){
if(n == 1)
cout << i;
n = n-1;
}
}
return 0;
}