I am trying to print a specific line from a textfile
e.g
I have a text file called info.txt and inside it contains the id,item name, price, quantity
Code:
1,shirt,100,10
2,pants,50,9
3,pen,20,8
I know how to find a specific word at the line in the file but how do I find and print out the specific line e.g(print out just the entire contents of line 2)?
Code:
string temDescription;
ofstream fout;
int curLine = 0;
ifstream readFile("info.txt");
cout << "Enter Item Description: ";
cin.ignore();
getline(cin, itemDescription);
while(getline(readFile, line)) {
curLine++;
if (line.find(itemDescription, 0) != string::npos) {
cout << "found: " << itemDescription << " at " << "line: " << curLine << endl;
}
}
readFile.close();
Please advise. thanks