fork download
  1. #include <cctype>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <fstream>
  5. #include <cstdlib>
  6. #include <cstring>
  7. #include <cmath>
  8. #include <cctype>
  9. #include <string>
  10. #include <ctime>
  11. using namespace std;
  12. void dateParse(string);
  13. int main()
  14. {
  15. string dte1 = "2/5/2014";
  16. string dte2 = "2/15/2014";
  17. string dte3 = "12/5/2014";
  18. string dte4 = "12/15/2014";
  19. string dts;
  20. dateParse(dte1);
  21. dateParse(dte2);
  22. dateParse(dte3);
  23. dateParse(dte4);
  24. }
  25. void dateParse(string date)
  26. {
  27. char day[2] = "";
  28. char month[2] = "";
  29. char year[5] = "";
  30. char buffer[80] = "";
  31. year = date.substr(date.find("/")+1,date.length());
  32. strcpy(buffer, year.c_str());
  33. strcpy(buffer, date.c_str());
  34. strcpy(day, strtok(buffer,"/"));
  35. strcpy(buffer, date.c_str());
  36. strcpy(year, strrchr(date.c_str(), '/'));
  37. for(int i = 0; i < 5; i++)
  38. {
  39. year[i] = year[i + 1];
  40. }
  41. strcpy(buffer, date.c_str());
  42. strcpy(buffer, ((strrchr(date.c_str(),'/')),(strchr(date.c_str(), '/') + 1)));
  43. strcpy(month, strtok(buffer,"/"));
  44. cout << "DAY: " << day << endl;
  45. cout << "MONTH: " << month << endl;
  46. cout << "YEAR: " << year << endl;
  47. cout << "--------------------------------" << endl;
  48. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘void dateParse(std::string)’:
prog.cpp:31:9: error: incompatible types in assignment of ‘std::basic_string<char>’ to ‘char [5]’
    year = date.substr(date.find("/")+1,date.length());
         ^
prog.cpp:32:24: error: request for member ‘c_str’ in ‘year’, which is of non-class type ‘char [5]’
    strcpy(buffer, year.c_str());
                        ^
stdout
Standard output is empty