
Untitled
By: a guest on
Apr 26th, 2012 | syntax:
None | size: 1.20 KB | hits: 12 | expires: Never
read file and tokenize data to compare to input in C
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
main () {
// string toks[];
char oneline[80],*del;
string line, creds[3], username, password;
int x = 0;
cout<<"Enter Username: ";
cin>>username;
cout<<"Enter Password: ";
cin>>password;
ifstream myfile;
myfile.open("jake.txt");
if (myfile.is_open())
{
while (!myfile.eof())
{
getline(myfile,line);
strcpy(oneline,line.c_str());
del = strtok(oneline,",");
while(del!=NULL)
{
creds[x] = del;
del = strtok(NULL,",");
++x;
}
if((creds[0]==username)&&(creds[1]==password))
{
cout<<creds[2]<<endl;
break;
}
}
myfile.close();
}
else
cout << "Unable to open file";
system("pause");
}
string oneline;
...
oneline = line;
...
#include<iostream>
#include<boost/tokenizer.hpp>
#include<string>
int tokenizer_main(int, char **){
using namespace std;
using namespace boost;
string s = "This,is,a,test";
tokenizer<> tok(s);
for(tokenizer<>::iterator beg=tok.begin(); beg!=tok.end();++beg){
cout << *beg << "n";
}
}
This
is
a
test