User identified input from computer

Hello, I am currently working on to create text to Binary converter. There is no problem in the code. However I want to type the text(to convert it into binary) after the build of the code. I tried to find a way by using cin so that I could enter the text after the build, but it doesn't work. Is there a way to type the text after the build?

There is no problem in the code below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
  #include <iostream>
  #include <bitset>
  using namespace std;

string TextToBinaryString(string words) {
    string binaryString = "";
    for (char& _char : words) {
        binaryString +=bitset<8>(_char).to_string();
    }
    return binaryString;
}
int main()
{
    string Text = "Hello world";
    cout << "text: " << Text << "\n";
    cout << "Convert text to binary: " << TextToBinaryString(Text) << "\n";
   
    return 0;
}
cin >> Text; //this does not work?! need to see error for it.
remember that >> operators and whitespace do not get along.
perhaps you want getline?
Last edited on
You're missing a required #include <string>

Include the required header file, then use the expected std::cin >> text.
Last edited on
Thank you!
Topic archived. No new replies allowed.