writing a code for console that analyzes binary

So, I am trying to write a c++ code that asks for a binary number and then after you can input the number you are looking for (IE 6125) and if it finds it inside of the binary number you input, it will show you the binary string that contains that number in the binary code you input this is what I have so far but am stumped as how to move forward

// ConsoleApplication3.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <string>
#include <iostream>
using namespace std;


int main()
{
string mystring;


mystring = "Enter the full Binary Code you wish for parsing";
cout << mystring << "\n";
cin <<
system("pause");
return 0;
}
wrote an altered code but I am getting errors that wont launch it. using visual studio for this

#include <iostream>
#include "stdafx.h"
using namespace std;

int main()
{
int n, c, k;
cout << "enter a number to be converted into binary";
cin >> n;
cout << "the binary number is";
for (c = 31; c >= 0; c--)
{
k = n >> c;
if (k & 1)
cout << "1";
else
cout << "0";

}
return 0;
}
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <string>
#include <bitset>
#include <limits>
#include <algorithm>

bool is_bit_string( const std::string& str )
{
    // http://en.cppreference.com/w/cpp/algorithm/all_any_none_of
    return std::all_of( std::begin(str), std::end(str),
                        [] ( char c ) { return c == '0' || c == '1' ; } ) ;
}

std::string get_bit_string()
{
    std::cout << "enter bit string: " ;
    static std::string str ;
    std::cin >> str ;

    if( is_bit_string(str) ) return str ;
    else
    {
        std::cout << "invalid input. try again\n" ;
        return get_bit_string() ;
    }
}

std::string to_bit_string( unsigned long long number )
{
    // http://en.cppreference.com/w/cpp/types/numeric_limits/digits
    constexpr std::size_t MAX_BITS = std::numeric_limits< unsigned long long >::digits ;

    // http://en.cppreference.com/w/cpp/utility/bitset
    // http://en.cppreference.com/w/cpp/utility/bitset/to_string
    const std::string str = std::bitset<MAX_BITS>(number).to_string() ;

    // remove leading zeroes
    // http://en.cppreference.com/w/cpp/string/basic_string/find
    const auto pos = str.find('1') ;
    return pos != std::string::npos ? str.substr(pos) : "0" ;
}

void print_search_result( const std::string& bit_str, unsigned long long number )
{
    const std::string num_str = to_bit_string(number) ;
    std::cout << "\n\nsearch for number: " << num_str << " (decimal " << number << ")\n"
              << "               in: " << bit_str << '\n' ;

    const std::size_t pos = bit_str.find(num_str) ;
    if( pos != std::string::npos )
    {
        const std::string space = std::string( pos, ' ' ) ;
        std::cout << "         found at: " << space << num_str
                  << "     (position [" << pos << "])\n" ;    }
    else std::cout << "**** not found\n" ;
}

int main()
{
    const std::string bits = get_bit_string() ;

    std::cout << "enter the number: " ;
    unsigned long long number ;
    std::cin >> number ;

    print_search_result( bits, number ) ;
}

http://coliru.stacked-crooked.com/a/e33038b20de999b3
I try running this new code you gave me but get tons of errors
wrote an altered code but I am getting errors that wont launch it. using visual studio for this

That code looks ok. I removed the #include "stdafx.h" since that is not standard, it's something to do with Visual Studio.

You didn't say what errors were - what was the error message(s)?

Anyway, it works here:
http://cpp.sh/552fh
1>------ Build started: Project: ConsoleApplication3, Configuration: Debug Win32 ------
1>ConsoleApplication3.cpp
1>c:\users\cschneider\source\repos\consoleapplication3\consoleapplication3\consoleapplication3.cpp(9): error C2039: 'string': is not a member of 'std'
1>c:\users\cschneider\source\repos\consoleapplication3\consoleapplication3\predefined c++ types (compiler internal)(208): note: see declaration of 'std'
1>c:\users\cschneider\source\repos\consoleapplication3\consoleapplication3\consoleapplication3.cpp(9): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\cschneider\source\repos\consoleapplication3\consoleapplication3\consoleapplication3.cpp(9): error C2143: syntax error: missing ',' before '&'
1>c:\users\cschneider\source\repos\consoleapplication3\consoleapplication3\consoleapplication3.cpp(12): error C2039: 'all_of': is not a member of 'std'

these are the errors I get all the way down and I am not sure why I am getting them
From a google search for
error C2039: 'string': is not a member of 'std' usually says it is because the header
 
#include <string> 
is missing or incorrect in some way.

error C2039: 'all_of': is not a member of 'std'
Most like likely a missing #include <algorithm>

Are you sure you copied JLBorges code completely, without missing something?



I got it to work finally for some reason I just had to change my compiler to c++11 and it worked like a charm thanks guys
Topic archived. No new replies allowed.