| | |
Please help!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2008
Posts: 25
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#include <iostream.h> #include <string.h> #include <vector.h> #include <fstream.h> using std::string; using std::vector; void function(vector<string>&fn,vector<string>&fnum,vector<string>&ln,vector<string>&lnum); void main() { ifstream fin,f2,f3,f4; //First name input vector <string> fname(25); fin.open("firstname.dat", ios :: in); for( int i= 0;i<25;i++) fin>>fname[i]; fin.close(); //Second name input vector <string> fnum(25); f2.open("firstnum.dat", ios :: in); for(int i= 0;i<25;i++) f2>>fnum[i]; f2.close(); //Third Name vector <string> lname(25); f3.open("lastname.dat", ios :: in); for( int i= 0;i<25;i++) f3>>lname[i]; f3.close(); //Forth Name vector <string> lnum(25); f4.open("lastnum.dat", ios :: in); for( int i= 0;i<25;i++) f4>>lnum[i]; f4.close(); function(fname,fnum,lname,lnum); } void function(vector<string>&fn,vector<string>&fnum,vector<string>&ln,vector<string>&lnum) { for(int i=0;i<25;i++) { cout<<fnum[i]<<'\t'<<fn[i]<<'\t'<<ln[i]<<'\t'<<lnum[i]<<endl; } }
Files attached below
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:
C++ Syntax (Toggle Plain Text)
string ln; for( int i= 0;i<25;i++) { fin >> ln; fname.push_back(ln); }
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.
![]() |
Other Threads in the C++ Forum
- Previous Thread: this->form2instance.Show();
- Next Thread: converting a String obj to an istream obj
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






