Welcome to Dream.In.Code
Become a C++ Expert!

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




Formatting my outData

 
Reply to this topicStart new topic

Formatting my outData

eadams20
30 Sep, 2006 - 09:53 AM
Post #1

D.I.C Head
**

Joined: 30 Aug, 2006
Posts: 65


My Contributions
CODE
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>

using namespace std;

int main()
{
  ifstream inData;
  string emailAddy;
  ofstream outData;
  

  inData.open("mail.dat");
  outData.open("addresses.dat");



  while(inData)
  
  {
    
    
    inData >> emailAddy;
    if(emailAddy.find('@') != string::npos)
    outData<<emailAddy;
  
  }

    
    outData<<"Email addresses:";
    inData.close();
    outData.close();



   cin.get();
   return 0;
}



My code works GREAT but I don't like the way it prints out in the address.dat file. it prints like this
QUOTE

Eadams20@youmail.comHeyYou@youmail.comEmail addresses:


I want it to print as such

QUOTE

Email Addresses:
Eadams20@youmail.com
HeyYou@youmail.com


I tried to do the cout << setw(14) << "Email Addresses: " << emailaddy << endl;

but it only formats the Run program and not the address.dat file

Thanks in advance..

Emily

edit: added [code] tags ~ jayman9

This post has been edited by Dark_Nexus: 1 Oct, 2006 - 02:30 PM
User is offlineProfile CardPM
+Quote Post

Vextor
RE: Formatting My OutData
30 Sep, 2006 - 07:12 PM
Post #2

D.I.C Regular
Group Icon

Joined: 22 May, 2002
Posts: 288



Thanked: 1 times
Dream Kudos: 25
My Contributions
I may not be understanding you correctly but if I am all you should have to do is output an new line or endl statment.

CODE

outData<<endl;


This post has been edited by Vextor: 30 Sep, 2006 - 07:14 PM
User is offlineProfile CardPM
+Quote Post

Xing
RE: Formatting My OutData
30 Sep, 2006 - 07:59 PM
Post #3

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 2 times
Dream Kudos: 1575
My Contributions
outData<<emailAddy<<'\n';
User is offlineProfile CardPM
+Quote Post

eadams20
RE: Formatting My OutData
30 Sep, 2006 - 08:36 PM
Post #4

D.I.C Head
**

Joined: 30 Aug, 2006
Posts: 65


My Contributions
CODE





#include <iostream>  //for accessing  cout statements
#include <fstream>   // for file i/o
#include <string>    
#include <iomanip>   //for accessing maniupulators

using namespace std;

int main()
{
  ifstream inData;   // for file input mail
  string emailAddy;  // for sorting the @ emails
  ofstream outData;  // for file output addresses
  

  inData.open("mail.dat");        //input file
  outData.open("addresses.dat");  //output file

  while(inData)                      // Loop

  
  {
    
    
    inData >> emailAddy;
    outData<<"Email addresses:";
  
    
    if(emailAddy.find('@') != string::npos)
    outData<<emailAddy;
    outData<<endl;
  
  }
    inData.close();
    outData.close();
    
    



   cin.get();
   return 0;
}



Here is how I fixed it now I get this in my addresses.dat

Email addresses:
Email addresses:Eadams20@youmail.com
Email addresses:
Email addresses:
Email addresses:
Email addresses:
Email addresses:
Email addresses:HeyYou@youmail.com
Email addresses:
Email addresses:
Email addresses:
Email addresses:
Email addresses:
Email addresses:
Email addresses:
QUOTE(Vextor @ 30 Sep, 2006 - 08:12 PM) *

I may not be understanding you correctly but if I am all you should have to do is output an new line or endl statment.

CODE

outData<<endl;



This post has been edited by eadams20: 30 Sep, 2006 - 08:38 PM
User is offlineProfile CardPM
+Quote Post

Vextor
RE: Formatting My OutData
30 Sep, 2006 - 08:55 PM
Post #5

D.I.C Regular
Group Icon

Joined: 22 May, 2002
Posts: 288



Thanked: 1 times
Dream Kudos: 25
My Contributions
Well you're getting an obscene repetition of 'email Addresses" because that statment is within the loop. What you need to do is move the [ outData<<"Email Addresses: "; ] statement to just before the code enters the loop. This will prevent it from being printed like it is.
User is offlineProfile CardPM
+Quote Post

eadams20
RE: Formatting My OutData
30 Sep, 2006 - 09:02 PM
Post #6

D.I.C Head
**

Joined: 30 Aug, 2006
Posts: 65


My Contributions
Thank you Thank you Thank you!!!! you Rock!!!


QUOTE(Vextor @ 30 Sep, 2006 - 09:55 PM) *

Well you're getting an obscene repetition of 'email Addresses" because that statment is within the loop. What you need to do is move the [ outData<<"Email Addresses: "; ] statement to just before the code enters the loop. This will prevent it from being printed like it is.

User is offlineProfile CardPM
+Quote Post

Vextor
RE: Formatting My OutData
30 Sep, 2006 - 09:13 PM
Post #7

D.I.C Regular
Group Icon

Joined: 22 May, 2002
Posts: 288



Thanked: 1 times
Dream Kudos: 25
My Contributions
QUOTE(eadams20 @ 30 Sep, 2006 - 11:02 PM) *

Thank you Thank you Thank you!!!! you Rock!!!


QUOTE(Vextor @ 30 Sep, 2006 - 09:55 PM) *

Well you're getting an obscene repetition of 'email Addresses" because that statment is within the loop. What you need to do is move the [ outData<<"Email Addresses: "; ] statement to just before the code enters the loop. This will prevent it from being printed like it is.




lol, No problem. If you have any more questions just drop in and somone should be able to help. Good luck.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 02:46AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month