T
Thomas J. Gritzan
yogi_bear_79 said:int main ()
{
char longDate[20];
cout << " \n Enter a date in the following format(February 27,
2008):";
cin.getline(longDate,20);
cout << day_of_the_week(longDate);
}
int day_of_the_week(char longDate[])
{
char* nextToken;
int a, b, c, d, r, w, x, y, z;
char *month = strtok_s(longDate, " ", &nextToken);
char *day = strtok_s(NULL, " ", &nextToken);
char *year = strtok_s(NULL, "\0", &nextToken);
......
This is the code, it seems fairly simple to me, it splits the input
date (given format) into the three sections, and it works great, I
have no idea how to attain the same resutls with std::string
Look:
#include <string>
#include <sstream>
#include <iostream>
void process(const std::string& date)
{
std::istringstream tok(date);
std::string month, day, year;
tok >> month >> day >> year;
std::string century = year.substr(0,2);
std::string year2 = year.substr(2,4);
}
int main()
{
std::cout << "Enter a date (ex. Feb 27 2008): ";
std::string date;
std::getline(std::cin, date);
process(date);
}
Add error checking as needed.
The FAQ covers the convertion from string to ints:
http://www.parashift.com/c++-faq-lite/misc-technical-issues.html