Converting from int to string doesnt work

Hello folks,
im creating a program, that checks whether a number is a Neon Number (a number where the digits of the square of the number are equal to the number itself so for example 9*9 = 81, 8+1 = 9). Im creating an int, asking user for input and wanna convert it to string now. The errors I get are the following (Visual Studio 2015)
to_string is not a member of "std"
to_string identifier not found

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 #include <string> 

#include "stdafx.h" 
#include <iostream> 
using std::cout; 
using std::cin; 
using std::string; 
  
int main() 
{ 
    std::cout << "NEON NUMBER TESTER \n enter your number \n"; 
    int number; 
    cin >> number; 
    string numberstr = std::to_string(number); 
    int firstnr = numberstr[0]; 
    cout << firstnr; 
    cin.get(); 
}
this can be done without using strings:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <algorithm>
#include <deque>

int main()
{
    std::cout << "enter number: \n";
    int num{};
    std::cin >> num;
    int num_sq = num*num;
    std::deque<int> digits{};
    while (num_sq)
    {
        digits.push_front(num_sq%10);
        num_sq /= 10;
    }

    std::cout << ((std::accumulate(digits.begin(), digits.end(), 0) == num) ? "neon \n" : "non-neon \n" ) << "\n";
}

btw, does someone have a list of neon nos other than 9, that's the only neon number i could find so far? thanks
It seems neon number are extremely rare. I tested it till 1000000 but still didn't find any after 81.
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
#include <iostream>
#include <algorithm>
#include <numeric>

using namespace std;

bool is_neon(int num, int square_root)
{
  int sum = 0;

  while (num > 0)
  {
    sum += (num % 10);
    num = num / 10;
  }
  return sum == square_root;
}

int main()
{
  for (int num = 2; num < 1000000; num++)
  {
    if (is_neon(num * num, num))
    {
      cout << "Neon number: " << num * num << "\n";
    }
  }
  return 0;
}
> for (int num = 2; num < 1000000; num++)
¿why do you start at 2?
I don't see why you don't consider 0 and 1 valid neon numbers.


@OP: enable c++11 when compilling.
It was just a typo, should have been 1
¿so why do you keep ignoring 0?
Somehow I was thinking that 0 is not a valid number - probably it was too late.
Topic archived. No new replies allowed.