Saturday, May 22, 2010

String function help in C++?

Hi i need to make a program where you enter the date as dd/mm/yy using cin and then it writes out the following:


Date:dd


Month:yy


Year:yy





I know i need to use cout for the output, i am new to C++ but here is my attempt and the code does not compile can somebody please help me?





#include %26lt;iostream%26gt;


#include %26lt;string%26gt;


using namespace std;





int main ()


{


string dd;


string mm;


string yy;





cout %26lt;%26lt; "Enter the date:";


getline(cin,dd/mm/yy);


cout%26lt;%26lt;"date"%26lt;%26lt;dd %26lt;%26lt;endl;


cout%26lt;%26lt;"month"%26lt;%26lt;mm%26lt;%26lt;endl;


cout%26lt;%26lt;"year"%26lt;%26lt;yy%26lt;%26lt;endl;


cin%26gt;%26gt;iQuit;


return 0;


}

String function help in C++?
int main()


{


char date[9];


cout %26lt;%26lt; "Enter the date:";


gets(date);


cout%26lt;%26lt;"date"%26lt;%26lt;date[0]%26lt;%26lt;date[1] %26lt;%26lt;endl;


cout%26lt;%26lt;"month"%26lt;%26lt;date[3]%26lt;%26lt;date[4] %26lt;%26lt;endl;


cout%26lt;%26lt;"year"%26lt;%26lt;date[6]%26lt;%26lt;date[7] %26lt;%26lt;endl;


return 0;


}
Reply:Actually, it should be int main.


The ANSI/ISO standard defines the entry point main for a C program as:


int main(int argc, char *argv[], char **env)


Of course, most compilers just let you write


main()


and get away with it.


I believe the first answerer took away my program.
Reply:1)well...the simple solution is tht it shud b :





#inlcude%26lt;iostream.h%26gt;


#inlcude%26lt;string.h%26gt;





2) the above prog, writren by ionut seems pretty kwl, xcpt fr th fact tht it shud b void main (), nt nt int main()








cheers


No comments:

Post a Comment