Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 131,691 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,462 people online right now. Registration is fast and FREE... Join Now!




QUIZ..testing your skills

 
Reply to this topicStart new topic

QUIZ..testing your skills, What does the program do

bluesuus
post 26 Dec, 2005 - 06:18 PM
Post #1


D.I.C Head

Group Icon
Joined: 26 Dec, 2005
Posts: 57



Dream Kudos: 25
My Contributions


HI guys...My name is mustapha.i have posted below a c++ program that i wrote and i want anyone to tell me what it does......and for those who have questions..they shud ask...ill be posting a lot of other Quizez to.

here is the code.....

Description: imagine you have a file called mail.dat.the file contains some message and some email addreesses...Tell me what the program does?

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main()
{
string::size_type position;

string part;

ifstream in;

ofstream out;


in.open("mail.dat");
if ( !in )
{
cout <<"Unable to read file\n";
return 1;
}

out.open("address.dat");
if( !out )
{
cout <<"Unable to open a new file\n";
return 1;
}

in >> part;


while ( in )
{
position = part.find('@');

if ( position != string::npos )
{
out << part;
out << "\n";
}
in >> part;
}

cout << "program ended successfully\n";

return 0;
}
User is offlineProfile CardPM

Go to the top of the page


unreal_origin
post 26 Dec, 2005 - 06:52 PM
Post #2


Wisdom Listens

Group Icon
Joined: 21 Apr, 2005
Posts: 700



Dream Kudos: 60
My Contributions


I am not to great with C++ but i have a question what would be in the file address.dat
User is offlineProfile CardPM

Go to the top of the page

fyrestorm
post 26 Dec, 2005 - 06:57 PM
Post #3


D.I.C Lover

Group Icon
Joined: 4 Apr, 2002
Posts: 3,103



Thanked 1 times

Dream Kudos: 228
My Contributions


that's the file that the program outputs to...
User is offlineProfile CardPM

Go to the top of the page

born2c0de
post 26 Dec, 2005 - 08:43 PM
Post #4


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,895



Thanked 34 times

Dream Kudos: 2800

Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions


I'm not so familiar with the string class but I think it truncates the email address to only the username before the '@' sign and writes it to address.dat
User is offlineProfile CardPM

Go to the top of the page

Amadeus
post 27 Dec, 2005 - 06:37 AM
Post #5


g++ -o drink whiskey.cpp

Group Icon
Joined: 12 Jul, 2002
Posts: 12,163



Thanked 32 times

Dream Kudos: 25
My Contributions


I have to say, this looks like an assignment to me...but if you want to what it does...make a file with one email address and some garbage text, and see what it does.
User is online!Profile CardPM

Go to the top of the page

Mrafcho001
post 27 Dec, 2005 - 09:47 AM
Post #6


D.I.C Addict

Group Icon
Joined: 1 Nov, 2005
Posts: 753



Thanked 5 times

Dream Kudos: 120
My Contributions


It just copies one file into the other.

It does search for the '@' sign but it does not do anything with that. The whole thing is copied.
User is offlineProfile CardPM

Go to the top of the page

born2c0de
post 27 Dec, 2005 - 08:53 PM
Post #7


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,895



Thanked 34 times

Dream Kudos: 2800

Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions


Thanks.
What does npos in string::npos stand for?
User is offlineProfile CardPM

Go to the top of the page

bluesuus
post 27 Dec, 2005 - 09:18 PM
Post #8


D.I.C Head

Group Icon
Joined: 26 Dec, 2005
Posts: 57



Dream Kudos: 25
My Contributions


Actually string::npos is a specail value that is returned when a match has not been found.It is the largest possible value of type string::size_type.it is usallay a number like 4294967295 on some machines.
User is offlineProfile CardPM

Go to the top of the page

born2c0de
post 28 Dec, 2005 - 05:55 AM
Post #9


printf("I'm a %XR",195936478);

Group Icon
Joined: 26 Nov, 2004
Posts: 3,895



Thanked 34 times

Dream Kudos: 2800

Expert In: 80x86 Assembly, C/C++, VB6, VB.NET, C#, J2SE, Win32 API, Reversing

My Contributions


Hmm...neat.
Thanks for the help.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/20/08 08:20AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month