int x;
cin >> x;
//If user writes 05 in x. Then I want that 05 should be printed when we cout << x;
//If user writes 005 when prompted for x then printing x should print 005, because 005 may be a telephone extension.
Is there any way?
MRehanQadri 0 Junior Poster in Training
Recommended Answers
Jump to PostTake the input in as a string.
#include <string> // to use the string class #include <iostream> using namespace std; int main() { string input; cout << "Enter number: "; getline(cin, input); cout << "You entered: " << input << endl; cin.get(); // pause program return 0; …
Jump to PostBecause it's required in the Assignment.
Then I suspect you've misinterpreted the assignment. Could you post it?
Jump to PostThis might work for you.
But then again, maybe not. You don't know beforehand how many leading 0s there are. And there is no way to find out unless it's a string.
All 9 Replies
NathanOliver 429 Veteran Poster Featured Poster
AnathemA_ 0 Newbie Poster
MRehanQadri 0 Junior Poster in Training
AnathemA_ 0 Newbie Poster
MRehanQadri 0 Junior Poster in Training
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
AnathemA_ 0 Newbie Poster
AnathemA_ 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.