Although character data types such as char are intrinsically numeric, whenever you print a char you automatically print the symbol associated with the character code (the char's value), never the code. In order to print the code you must cast the character to a numeric data type, such as int. char c = 'A'; // ASCII value 65 decimal (0x41) std::cout << static_cast<int>(c); // puts the value 65 on std::cout
#include<iostream> #include<string> #include<sstream> int main() { for (size_t employee=1; employee<=5; ++employee) { bool ok = false; while (!ok) { std::string input; std::cout << "Employee #" << employee << std::endl; std::cout << "Enter basic pay: "; std::getline (std::cin, input); std::stringstream ss; ss << input; double pay; if (ss >> pay) { double allowance = pay * 20 / 100; double tax = (pay-allowance) * 30 / 100; double nett = pay - tax; std::cout << "Basic pay:\t" << pay << std::endl; std::cout << "Allowance:\t" << allowance << std::endl; std::cout << "Tax:\t\t" << tax << std::endl; std::cout << "Nett:\t\t" << nett << std::endl; ok = true; } else { std::cout << "Bad input\n"; } } std::cout << std::endl; } }
#include<iostream> int main() { std::cout << "sin(1) = " << std::sin(1.0) << std::endl; std::cout << "cos(1) = " << std::cos(1.0) << std::endl; std::cout << "tan(1) = " << std::tan(1.0) << std::endl; std::cout << "asin(1) = " << std::asin(1.0) << std::endl; std::cout << "acos(1) = " << std::acos(1.0) << std::endl; std::cout << "atan(1) = " << std::atan(1.0) << std::endl; } Output: sin(1) = 0.841471 cos(1) = 0.540302 tan(1) = 1.55741 asin(1) = 1.5708 acos(1) = 0 atan(1) = 0.785398
#include<iostream> #include<vector> #include<string> std::vector<std::string> parse (const std::string& s, const char delim) { std::vector<std::string> result {}; auto start = 0U; auto end = s.find (delim); while (end != s.npos) { result.push_back (s.substr(start, end - start)); start = ++end; end = s.find (delim, start); } result.push_back (s.substr (start, s.npos - start)); return result; } std::vector<std::string> parse (const std::string& s, const std::string& delim) { std::vector<std::string> result {}; auto start = 0U; auto end = s.find (delim); while (end != s.npos) { result.push_back (s.substr(start, end - start)); start = end + delim.length(); end = s.find (delim, start); } result.push_back (s.substr (start, s.npos - start)); return result; } int main() { std::string str1 = "This is a string that will be parsed by a single-space delimiter."; std::string str2 = "This==is==a==string==that==will==be==parsed==by==equal==operator."; std::string str3 = "This string has no delimiter."; std::cout << str1 << std::endl; std::vector<std::string> v1 = parse (str1, ' '); for (auto i : v1 ) std::cout << i << std::endl; std::cout << std::endl; std::cout << str2 << std::endl; std::vector<std::string> v2 = parse (str2, "=="); for (auto i : v2 ) std::cout << i << std::endl; std::cout << std::endl; std::cout << str3 << std::endl; std::vector<std::string> v3 = parse (str3, '\\'); for (auto i : v3 ) std::cout << i << std::endl; std::cout << std::endl; }
No, the use of 'namespace std' is not compulsory. You can specifiy it on any object reference. Specifying 'namespace' simply provides a default value. Contrast ... using namespace std; cout << "Hello world!" << endl; ... with ... std::cout << "Hello world!" << std::endl;
STD code for France is 0033
I'm guessing that you mean STD = Subscriber Trunk Dialling (telephone area code) rather than STD = Sexually Transmitted Disease. STD code is another term used in some country for telephone area codes. The purpose of a telephone area code is to group telephone numbers by geographic area. In many cases, at least some calls to numbers with the same STD code as the caller can be dialed without the STD code, allowing shorter dialing sequences for many local calls.
01409 area code Holsworthy
01234245
01224246
The std code starts with 022
Oh, dude, STD code 0140 is for the city of Ghaziabad in India. So, if you're planning a prank call or just need to reach someone in Ghaziabad, now you know where to dial. Just remember, always use your powers for good, not evil... or at least for a good laugh.
THE STD CODE OF KULTI IS 0341.
In India, each city and state is assigned a Subscribing Trunk Dalling (STD) code. Once the city and state is provided, a STD code can be matched for that location.
#include<iostream> #include<conio.h> #include<string> int main() { std::cout << "Enter your 10 digit code: "; size_t code=0; size_t len=0; while (len<10) { char c = (char) _getch(); if (c=='0' && !code) // leading zero not permitted! continue; if (c>='0' && c<='9') { ++len; std::cout << c; c -= '0'; code *= 10; code += c; } } std::cout << "\n\nYou entered: " << code << '\n' << std::endl; }
There are a considerable number - each town has it own STD code
An example of an STD (Subscriber Trunk Dialling, or customer-dialed long-distance) call from Sydney would be a call to Melbourne. You dial the STD Code (telephone area code) for Melbourne, 03, followed by the 8-digit local number.