Please help!

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jan 2008
Posts: 25
Reputation: Alishaikh is an unknown quantity at this point 
Solved Threads: 0
Alishaikh Alishaikh is offline Offline
Light Poster

Please help!

 
0
  #1
May 12th, 2008
  1. #include <iostream.h>
  2. #include <string.h>
  3. #include <vector.h>
  4. #include <fstream.h>
  5. using std::string;
  6. using std::vector;
  7. void function(vector<string>&fn,vector<string>&fnum,vector<string>&ln,vector<string>&lnum);
  8. void main()
  9. {
  10. ifstream fin,f2,f3,f4;
  11. //First name input
  12. vector <string> fname(25);
  13. fin.open("firstname.dat", ios :: in);
  14. for( int i= 0;i<25;i++)
  15. fin>>fname[i];
  16. fin.close();
  17. //Second name input
  18. vector <string> fnum(25);
  19. f2.open("firstnum.dat", ios :: in);
  20. for(int i= 0;i<25;i++)
  21. f2>>fnum[i];
  22. f2.close();
  23. //Third Name
  24. vector <string> lname(25);
  25. f3.open("lastname.dat", ios :: in);
  26. for( int i= 0;i<25;i++)
  27. f3>>lname[i];
  28. f3.close();
  29. //Forth Name
  30. vector <string> lnum(25);
  31. f4.open("lastnum.dat", ios :: in);
  32. for( int i= 0;i<25;i++)
  33. f4>>lnum[i];
  34. f4.close();
  35. function(fname,fnum,lname,lnum);
  36.  
  37. }
  38. void function(vector<string>&fn,vector<string>&fnum,vector<string>&ln,vector<string>&lnum)
  39. {
  40. for(int i=0;i<25;i++)
  41. {
  42.  
  43. cout<<fnum[i]<<'\t'<<fn[i]<<'\t'<<ln[i]<<'\t'<<lnum[i]<<endl;
  44. }
  45. }
I need to make so the First Numbers and names display along with their last name counterparts in the functions
Files attached below
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 25
Reputation: Alishaikh is an unknown quantity at this point 
Solved Threads: 0
Alishaikh Alishaikh is offline Offline
Light Poster

Re: Please help!

 
0
  #2
May 12th, 2008
Files below
Attached Files
File Type: zip Files.zip (2.2 KB, 1 views)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,596
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1488
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Please help!

 
0
  #3
May 12th, 2008
Your read loops are incorrect. There is a couple extra steps you have to take. The vectors are initially empty, so one way to do it is to append each string like this:
  1. string ln;
  2. for( int i= 0;i<25;i++)
  3. {
  4. fin >> ln;
  5. fname.push_back(ln);
  6. }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC