| | |
parsing date strings mm/dd/yy??
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Here's a start:
C++ Syntax (Toggle Plain Text)
#include <cstdlib> #include <iostream> #include <sstream> #include <string> using namespace std; int main() { istringstream in ( "03/30/05" ); int m, d, y; in>> m; if ( in.peek() != '/' ) { cerr<<"Invalid format"<<endl; return EXIT_FAILURE; } in.ignore(); in>> d; if ( in.peek() != '/' ) { cerr<<"Invalid format"<<endl; return EXIT_FAILURE; } in.ignore(); in>> y; cout<< m <<' '<< d <<' '<< y <<endl; }
I'm here to prove you wrong.
•
•
Join Date: Mar 2005
Posts: 7
Reputation:
Solved Threads: 0
Thanks for the code, however, I'm really at a loss to how it works. We've not yet gone this far in C++, only arrays & some work with strings. Can I put a cout prompt & cin to input the date this way? ex.
cout << "Input date in format mm/dd/yy :\n";
char date[9];
cin >> date;
As I have to error check the date, and later output it in a function converting to monthname dd, 20##.
cout << "Input date in format mm/dd/yy :\n";
char date[9];
cin >> date;
As I have to error check the date, and later output it in a function converting to monthname dd, 20##.
>We've not yet gone this far in C++
Oh, so this is homework? In that case you'll need to show some effort in the form of an existing attempt, or detailed examples of what steps you went through while trying to figure out a solution and what you learned in the process. And posting here doesn't count.
Oh, so this is homework? In that case you'll need to show some effort in the form of an existing attempt, or detailed examples of what steps you went through while trying to figure out a solution and what you learned in the process. And posting here doesn't count.
I'm here to prove you wrong.
![]() |
Similar Threads
- Program, help (Java)
- Escaping symbols in strings? (Pascal and Delphi)
- Parsing a date into MM/DD/YYYY HH:MM:SS format (Python)
Other Threads in the C++ Forum
| Thread Tools | Search this Thread |
api application array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






