in Education by
I am a beginner and I just need a bit of help on why I getline is showing an error: this is what I have so far #include #include #include #include using namespace std; const double TAX_RATE = 0.0825; const int MAX_ITEMS = 1000; const int MAX_TRANSACTIONS = 100; int main(int argc, char const *argv[]){ string fname = ""; int itemCnt = 0, start = 0, end = 0; int ids[MAX_ITEMS], qtys[MAX_ITEMS]; double costs[MAX_ITEMS], subtotals[MAX_TRANSACTIONS], taxes[MAX_TRANSACTIONS], totals[MAX_TRANSACTIONS]; string names[MAX_ITEMS], paymentTypes[MAX_ITEMS], payments[MAX_ITEMS]; ifstream iFile; if ( argc != 2 ) { cout<<"usage: "<< argv[0]<< " <file name>" <<endl; return 0; } else { iFile.open(argv[1]); } if (!iFile) { cout<<"Error: Invalid file name"<<endl; cin.clear(); } while (!iFile.eof()) { getline(iFile,str); //this isn't working int commaLoc = str.find(','); ids[itemCnt]= str.substr(0,commaLoc); str = str.substr(commaLoc +1, str.length()); //string to int I'm not sure how to do I know its something with stoi() but not sure how to format it } return 0; } I am able to get the file to open but I'm not sure why getline isn't working it keeps saying something like no instance of overload function My csv file looks like: 1,Laptop,799.99,1,cash,1100 I need it to read the first number and because Its a string i don't know how to save it as an int JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Multiple errors. First there is nothing called 'str' in your program. I will guess its just a string used as a temp buffer do not do this (!File.eof) it doesnt do what you think. while (iFile) { string str; <<<<<==== added getline(iFile,str); //this isn't working <<<===is now int commaLoc = str.find(','); Next this line doesnt work because ids are ints and substring returns a string. // ids[itemCnt]= str.substr(0,commaLoc); ids[itemCnt]= stoi(str.substr(0,commaLoc)); <<<<==== fixed str = str.substr(commaLoc +1, str.length()); } I strongly recommend you use std::vector instead of c-style fixed size arrays. Takes 5 minutes to learn how to use them and they have huge benefits. If you must use fixed size arrays use std::array instead of c-style

Related questions

0 votes
    I am a beginner and I just need a bit of help on why I getline is showing an error: this is what I have so far ... payments[MAX_ITEMS]; ifstream iFile; if ( argc != 2 ) { cout...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    Which of the following statement can read csv files? (a) read.table(filename,header=TRUE,sep=',') (b) ... Regression of R Programming Select the correct answer from above options...
asked Feb 10, 2022 in Education by JackTerrance
0 votes
    In the following code : #include #include #include using namespace std; int main() { string x = "This ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    In the following code : #include #include #include using namespace std; int main() { string x = "This ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 26, 2022 in Education by JackTerrance
0 votes
    __________ function is used for reading the .csv file in R language. (a) Write.csv() (b) Read.csv () ... and Debugging of R Programming Select the correct answer from above options...
asked Feb 12, 2022 in Education by JackTerrance
0 votes
    I'm relatively new to C++, and I'm hoping someone can help me resolve an issue I'm having with unique_ptr and vectors. ... ) { useLegs(); } void Biped::useLegs() { std::cout...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    This question already has answers here: How to concatenate a std::string and an int (24 answers) Closed 5 years ago. int i = 4; string text = "Player "; cout...
asked Mar 24, 2022 in Education by JackTerrance
0 votes
    Which component do you need to use in order to read data line by line from an input flow ... entries into iterative global variables? tIterateToFlow tFileList tFlowToIterate tLoop...
asked Mar 24, 2021 in Technology by JackTerrance
0 votes
    I'm looking to have two versions of BOOST compiled into a project at the same time. Ideally they ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 22, 2022 in Education by JackTerrance
0 votes
    I'm looking to have two versions of BOOST compiled into a project at the same time. Ideally they ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
0 votes
    I'm looking to have two versions of BOOST compiled into a project at the same time. Ideally they ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 20, 2022 in Education by JackTerrance
0 votes
    I work on graphics applications and have been using shared & unique pointers essentially because it handles memory ... for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 30, 2022 in Education by JackTerrance
0 votes
    A csv file consists of missing values that are represented by hashtags (“#”) and ampersands (“&”). How can you read this type of a csv file in R?...
asked Oct 16, 2020 in Technology by JackTerrance
0 votes
    Can someone tell me any methods to read every line of a file in Python and store each line as an element in a ... till the end of list. Select the correct answer from above options...
asked Jan 21, 2022 in Education by JackTerrance
0 votes
    This is my code it's just starting the scan but it is not completing ,where is the error in it. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 26, 2022 in Education by JackTerrance
...