Searching in csv files in c++ [on hold]












-1












$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;


}










share|improve this question







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$



put on hold as off-topic by Jamal 1 hour ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.
















  • $begingroup$
    This site is only for improving code that already works. Your code does not seem ready for this site because the question includes "but the issue is". You should also post the complete code instead of only some fragments, and please let your IDE or editor format the code before you post it here. Right now it looks like a wall of characters because it is missing the usual space around the operators like <<.
    $endgroup$
    – Roland Illig
    3 hours ago


















-1












$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;


}










share|improve this question







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$



put on hold as off-topic by Jamal 1 hour ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.
















  • $begingroup$
    This site is only for improving code that already works. Your code does not seem ready for this site because the question includes "but the issue is". You should also post the complete code instead of only some fragments, and please let your IDE or editor format the code before you post it here. Right now it looks like a wall of characters because it is missing the usual space around the operators like <<.
    $endgroup$
    – Roland Illig
    3 hours ago
















-1












-1








-1





$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;


}










share|improve this question







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






share|improve this question







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.











share|improve this question







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.









share|improve this question




share|improve this question






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 4 hours 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.




put on hold as off-topic by Jamal 1 hour ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.







put on hold as off-topic by Jamal 1 hour ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – Jamal

If this question can be reworded to fit the rules in the help center, please edit the question.












  • $begingroup$
    This site is only for improving code that already works. Your code does not seem ready for this site because the question includes "but the issue is". You should also post the complete code instead of only some fragments, and please let your IDE or editor format the code before you post it here. Right now it looks like a wall of characters because it is missing the usual space around the operators like <<.
    $endgroup$
    – Roland Illig
    3 hours ago




















  • $begingroup$
    This site is only for improving code that already works. Your code does not seem ready for this site because the question includes "but the issue is". You should also post the complete code instead of only some fragments, and please let your IDE or editor format the code before you post it here. Right now it looks like a wall of characters because it is missing the usual space around the operators like <<.
    $endgroup$
    – Roland Illig
    3 hours ago


















$begingroup$
This site is only for improving code that already works. Your code does not seem ready for this site because the question includes "but the issue is". You should also post the complete code instead of only some fragments, and please let your IDE or editor format the code before you post it here. Right now it looks like a wall of characters because it is missing the usual space around the operators like <<.
$endgroup$
– Roland Illig
3 hours ago






$begingroup$
This site is only for improving code that already works. Your code does not seem ready for this site because the question includes "but the issue is". You should also post the complete code instead of only some fragments, and please let your IDE or editor format the code before you post it here. Right now it looks like a wall of characters because it is missing the usual space around the operators like <<.
$endgroup$
– Roland Illig
3 hours ago












0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

is 'sed' thread safe

How to make a Squid Proxy server?