32 lines
683 B
C++
32 lines
683 B
C++
|
// strfile.cpp -- read strings from a file
|
||
|
#include <iostream>
|
||
|
#include <fstream>
|
||
|
#include <string>
|
||
|
#include <cstdlib>
|
||
|
int main()
|
||
|
{
|
||
|
using namespace std;
|
||
|
ifstream fin;
|
||
|
fin.open("tobuy.txt");
|
||
|
if (fin.is_open() == false)
|
||
|
{
|
||
|
cerr << "Can't open file. Bye.\n";
|
||
|
exit(EXIT_FAILURE);
|
||
|
}
|
||
|
string item;
|
||
|
int count = 0;
|
||
|
|
||
|
getline(fin, item, ':');
|
||
|
while (fin) // while input is good
|
||
|
{
|
||
|
++count;
|
||
|
cout << count <<": " << item << endl;
|
||
|
getline(fin, item,':');
|
||
|
}
|
||
|
cout << "Done\n";
|
||
|
fin.close();
|
||
|
// std::cin.get();
|
||
|
// std::cin.get();
|
||
|
return 0;
|
||
|
}
|