Searching in csv files in c++
$begingroup$
ps this question only has part of my code
I take multiple inputs from user and store them in a csv file.
int NewEntry(){
cin.ignore();
string name,phno,id,date;
int Ecost,advance,due;
ofstream file("data.txt",ios::in|ios::out|ios::app);
if(file){
cout<<"Customer Name:-";
getline(cin,name);
cout<<"ID or Aadhar Card:-";
getline(cin,id);
cout<<"Phone number:-";
getline(cin,phno);
cout<<"Today's Date(dd/mm/yy):-";
getline(cin,date);
cout<<"Estimated Cost:-";
cin>>Ecost;
cout<<"Advance:-";
cin>>advance;
due=(Ecost-advance);
file<<name<<','
<<id<<','
<<phno<<','
<<date<<','
<<Ecost<<','
<<advance<<','
<<due
<<"n";
system("cls");
cout<<endl<<"Entry Created.";
file.close();
}
the data looks like this
Sumeet,11802638,8005958881,09-03-19,2000,1000,1000 //line ends here
Sagar,11802637,7788830892,13-09-19,1200,200,1000
Rohit,11802639,9998887776,10-09-19,2500,500,2000
then I apply search by name,id or phone number by this part of code
getline(cin,names);
while(getline(file,line)) {
stringstream ss(line);
getline(ss,name,',');
getline(ss,id,',');
getline(ss,phno,',');
getline(ss,date,',');
getline(ss,ecost,',');
getline(ss,advance,',');
getline(ss,due,'n');
if(names==name) {
cout<<"Name:-"<<name<<"nID:-"<<id<<"nPhone no:-"<<phno<<"nDate of Entry:-"<<date<<"nEstimated Cost:-"<<ecost<<"nAdvance Paid:-"<<advance<<"nAmount due:-"<<due<<endl;
}
similarly I apply search by id and number;
but the issue is my programs only searches in first line, if i search a name or id in second line it doesn't work.
where as if i print all the data in csv file it works just fine.
void AllDisplay(){
string date,id,name,phno,ecost,advance,due;
string line;
ifstream file("data.txt");
while (getline(file,line)) {
stringstream ss(line);
getline(ss,name,',');
getline(ss,id,',');
getline(ss,phno,',');
getline(ss,date,',');
getline(ss,ecost,',');
getline(ss,advance,',');
getline(ss,due,'n');
cout<<"Name:-"<<name<<"nID:-"<<id<<"nPhone no:-"<<phno<<"nDate of Entry:-"<<date<<"nEstimated Cost:-"<<ecost<<"nAdvance Paid:-"<<advance<<"nAmount due:-"<<due<<endl;
cout<<"-------------------------------------------"<<endl;
}
c++ file csv
New contributor
sumeet bansal Rahul is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
ps this question only has part of my code
I take multiple inputs from user and store them in a csv file.
int NewEntry(){
cin.ignore();
string name,phno,id,date;
int Ecost,advance,due;
ofstream file("data.txt",ios::in|ios::out|ios::app);
if(file){
cout<<"Customer Name:-";
getline(cin,name);
cout<<"ID or Aadhar Card:-";
getline(cin,id);
cout<<"Phone number:-";
getline(cin,phno);
cout<<"Today's Date(dd/mm/yy):-";
getline(cin,date);
cout<<"Estimated Cost:-";
cin>>Ecost;
cout<<"Advance:-";
cin>>advance;
due=(Ecost-advance);
file<<name<<','
<<id<<','
<<phno<<','
<<date<<','
<<Ecost<<','
<<advance<<','
<<due
<<"n";
system("cls");
cout<<endl<<"Entry Created.";
file.close();
}
the data looks like this
Sumeet,11802638,8005958881,09-03-19,2000,1000,1000 //line ends here
Sagar,11802637,7788830892,13-09-19,1200,200,1000
Rohit,11802639,9998887776,10-09-19,2500,500,2000
then I apply search by name,id or phone number by this part of code
getline(cin,names);
while(getline(file,line)) {
stringstream ss(line);
getline(ss,name,',');
getline(ss,id,',');
getline(ss,phno,',');
getline(ss,date,',');
getline(ss,ecost,',');
getline(ss,advance,',');
getline(ss,due,'n');
if(names==name) {
cout<<"Name:-"<<name<<"nID:-"<<id<<"nPhone no:-"<<phno<<"nDate of Entry:-"<<date<<"nEstimated Cost:-"<<ecost<<"nAdvance Paid:-"<<advance<<"nAmount due:-"<<due<<endl;
}
similarly I apply search by id and number;
but the issue is my programs only searches in first line, if i search a name or id in second line it doesn't work.
where as if i print all the data in csv file it works just fine.
void AllDisplay(){
string date,id,name,phno,ecost,advance,due;
string line;
ifstream file("data.txt");
while (getline(file,line)) {
stringstream ss(line);
getline(ss,name,',');
getline(ss,id,',');
getline(ss,phno,',');
getline(ss,date,',');
getline(ss,ecost,',');
getline(ss,advance,',');
getline(ss,due,'n');
cout<<"Name:-"<<name<<"nID:-"<<id<<"nPhone no:-"<<phno<<"nDate of Entry:-"<<date<<"nEstimated Cost:-"<<ecost<<"nAdvance Paid:-"<<advance<<"nAmount due:-"<<due<<endl;
cout<<"-------------------------------------------"<<endl;
}
c++ file csv
New contributor
sumeet bansal Rahul is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
add a comment |
$begingroup$
ps this question only has part of my code
I take multiple inputs from user and store them in a csv file.
int NewEntry(){
cin.ignore();
string name,phno,id,date;
int Ecost,advance,due;
ofstream file("data.txt",ios::in|ios::out|ios::app);
if(file){
cout<<"Customer Name:-";
getline(cin,name);
cout<<"ID or Aadhar Card:-";
getline(cin,id);
cout<<"Phone number:-";
getline(cin,phno);
cout<<"Today's Date(dd/mm/yy):-";
getline(cin,date);
cout<<"Estimated Cost:-";
cin>>Ecost;
cout<<"Advance:-";
cin>>advance;
due=(Ecost-advance);
file<<name<<','
<<id<<','
<<phno<<','
<<date<<','
<<Ecost<<','
<<advance<<','
<<due
<<"n";
system("cls");
cout<<endl<<"Entry Created.";
file.close();
}
the data looks like this
Sumeet,11802638,8005958881,09-03-19,2000,1000,1000 //line ends here
Sagar,11802637,7788830892,13-09-19,1200,200,1000
Rohit,11802639,9998887776,10-09-19,2500,500,2000
then I apply search by name,id or phone number by this part of code
getline(cin,names);
while(getline(file,line)) {
stringstream ss(line);
getline(ss,name,',');
getline(ss,id,',');
getline(ss,phno,',');
getline(ss,date,',');
getline(ss,ecost,',');
getline(ss,advance,',');
getline(ss,due,'n');
if(names==name) {
cout<<"Name:-"<<name<<"nID:-"<<id<<"nPhone no:-"<<phno<<"nDate of Entry:-"<<date<<"nEstimated Cost:-"<<ecost<<"nAdvance Paid:-"<<advance<<"nAmount due:-"<<due<<endl;
}
similarly I apply search by id and number;
but the issue is my programs only searches in first line, if i search a name or id in second line it doesn't work.
where as if i print all the data in csv file it works just fine.
void AllDisplay(){
string date,id,name,phno,ecost,advance,due;
string line;
ifstream file("data.txt");
while (getline(file,line)) {
stringstream ss(line);
getline(ss,name,',');
getline(ss,id,',');
getline(ss,phno,',');
getline(ss,date,',');
getline(ss,ecost,',');
getline(ss,advance,',');
getline(ss,due,'n');
cout<<"Name:-"<<name<<"nID:-"<<id<<"nPhone no:-"<<phno<<"nDate of Entry:-"<<date<<"nEstimated Cost:-"<<ecost<<"nAdvance Paid:-"<<advance<<"nAmount due:-"<<due<<endl;
cout<<"-------------------------------------------"<<endl;
}
c++ file csv
New contributor
sumeet bansal Rahul is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
$endgroup$
ps this question only has part of my code
I take multiple inputs from user and store them in a csv file.
int NewEntry(){
cin.ignore();
string name,phno,id,date;
int Ecost,advance,due;
ofstream file("data.txt",ios::in|ios::out|ios::app);
if(file){
cout<<"Customer Name:-";
getline(cin,name);
cout<<"ID or Aadhar Card:-";
getline(cin,id);
cout<<"Phone number:-";
getline(cin,phno);
cout<<"Today's Date(dd/mm/yy):-";
getline(cin,date);
cout<<"Estimated Cost:-";
cin>>Ecost;
cout<<"Advance:-";
cin>>advance;
due=(Ecost-advance);
file<<name<<','
<<id<<','
<<phno<<','
<<date<<','
<<Ecost<<','
<<advance<<','
<<due
<<"n";
system("cls");
cout<<endl<<"Entry Created.";
file.close();
}
the data looks like this
Sumeet,11802638,8005958881,09-03-19,2000,1000,1000 //line ends here
Sagar,11802637,7788830892,13-09-19,1200,200,1000
Rohit,11802639,9998887776,10-09-19,2500,500,2000
then I apply search by name,id or phone number by this part of code
getline(cin,names);
while(getline(file,line)) {
stringstream ss(line);
getline(ss,name,',');
getline(ss,id,',');
getline(ss,phno,',');
getline(ss,date,',');
getline(ss,ecost,',');
getline(ss,advance,',');
getline(ss,due,'n');
if(names==name) {
cout<<"Name:-"<<name<<"nID:-"<<id<<"nPhone no:-"<<phno<<"nDate of Entry:-"<<date<<"nEstimated Cost:-"<<ecost<<"nAdvance Paid:-"<<advance<<"nAmount due:-"<<due<<endl;
}
similarly I apply search by id and number;
but the issue is my programs only searches in first line, if i search a name or id in second line it doesn't work.
where as if i print all the data in csv file it works just fine.
void AllDisplay(){
string date,id,name,phno,ecost,advance,due;
string line;
ifstream file("data.txt");
while (getline(file,line)) {
stringstream ss(line);
getline(ss,name,',');
getline(ss,id,',');
getline(ss,phno,',');
getline(ss,date,',');
getline(ss,ecost,',');
getline(ss,advance,',');
getline(ss,due,'n');
cout<<"Name:-"<<name<<"nID:-"<<id<<"nPhone no:-"<<phno<<"nDate of Entry:-"<<date<<"nEstimated Cost:-"<<ecost<<"nAdvance Paid:-"<<advance<<"nAmount due:-"<<due<<endl;
cout<<"-------------------------------------------"<<endl;
}
c++ file csv
c++ file csv
New contributor
sumeet bansal Rahul is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
sumeet bansal Rahul is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
sumeet bansal Rahul is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 21 mins ago
sumeet bansal Rahulsumeet bansal Rahul
11
11
New contributor
sumeet bansal Rahul is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
sumeet bansal Rahul is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
sumeet bansal Rahul is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
});
});
}, "mathjax-editing");
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "196"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
sumeet bansal Rahul is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215710%2fsearching-in-csv-files-in-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
sumeet bansal Rahul is a new contributor. Be nice, and check out our Code of Conduct.
sumeet bansal Rahul is a new contributor. Be nice, and check out our Code of Conduct.
sumeet bansal Rahul is a new contributor. Be nice, and check out our Code of Conduct.
sumeet bansal Rahul is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f215710%2fsearching-in-csv-files-in-c%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown