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 Postif your using a telephone #, it sounds like you should be using a string instead of an int for this situation.
std::string strExt;
std::cin >> strExt << std::endl;
Jump to Postas far as i know no. Why do you want the extension as an integer?
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.