I was practising the question before the final semester exam, and I have a problem.
#include <iostream>
#include <string.h>
#include <cmath>
using namespace std;
int num; // A number needs to be entered
int o_num; // Original number
int r;
string str1 = "", str2 = "", temp = "";
void DigitToWord()
{
r = num % 10;
switch (r)
{
case 0:
str1 = "zero ";
break;
case 1:
str1 = "one ";
break;
case 2:
str1 = "two ";
break;
case 3:
str1 = "three ";
break;
case 4:
str1 = "four ";
break;
case 5:
str1 = "five ";
break;
case 6:
str1 = "six ";
break;
case 7:
str1 = "seven ";
break;
case 8:
str1 = "eight ";
break;
case 9:
str1 = "nine ";
break;
}
temp = str1;
str2 = str2 + temp;
}
int main()
{
do
{
cout << "Enter a positive integer (not more than 10000): ";
cin >> num;
} while (num < 0 || num > 10000);
o_num = num;
for (; num != 0; num = num / 10)
{
DigitToWord();
}
cout << endl << o_num << " : " << str2 << endl;
system("pause");
return 0;
}
When I was creating the code in VS 2013, I saw a red wavy line on "<<" before "str2" (line 78).
I got an error called:
Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)
If I input 756, the program must show an output like this:
756 : seven five six