0

hi guys i have problem in c++. i use dev c++. i have a .txt file like this:

|1|sugar|100|
|2|salt|200|

it's like a table but in .txt file.

from that data, after i input number/code value "1", i want to make an output like this:

name: sugar
quantity: 100

but using my code now, i still got an output same as in .txt file. Can someone help me so my code can make an output like i want above? Here's my code:

    void MyTransaction()
    {
     system("cls");
     string mycode,line;
     cout << "Input code : ";
     cin  >> mycode;

    ifstream newstream;
    newstream.open("mydatabase.txt",ifstream::in);

    size_t pos;
    while (newstream.good()){ 
                   getline(newstream,line);
                   pos=line.find(mycode);
                   if(pos!=string::npos) // string::npos is returned if string is not found
            {
                cout <<line;
                break;
            }
              }
    newstream.close();
}
Shumimura
  • 57
  • 2
  • 7

0 Answers0