Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <fstream>
- #include <vector>
- using namespace std;
- vector<string> split(const string& s, const char delimiter, bool ignore_empty = false){
- vector<string> result;
- string tmp = s;
- while(tmp.find(delimiter) != string::npos)
- {
- string new_part = tmp.substr(0, tmp.find(delimiter));
- tmp = tmp.substr(tmp.find(delimiter)+1, tmp.size());
- if(not (ignore_empty and new_part.empty()))
- {
- result.push_back(new_part);
- }
- }
- if(not (ignore_empty and tmp.empty()))
- {
- result.push_back(tmp);
- }
- return result;
- }
- bool is_number(const string& s)
- {
- string::const_iterator it = s.begin();
- while (it != s.end() && isdigit(*it)) ++it;
- return !s.empty() && it == s.end();
- }
- int main()
- {
- string tiedoston_nimi = "";
- cout << "Input file: ";
- getline(cin, tiedoston_nimi);
- ifstream tiedosto_olio(tiedoston_nimi);
- if ( not tiedosto_olio )
- {
- cout << "Error: the input file cannot be opened" << endl;
- return EXIT_FAILURE;
- }
- string rivi;
- while(getline(tiedosto_olio, rivi))
- {
- vector<string> rivi_vektori = split(rivi, ';');
- for (unsigned long int k = 0; k < rivi_vektori.size()-1; ++k)
- {
- cout << rivi_vektori.at(k) << endl;
- }
- if (rivi_vektori.size() != 3 or !(is_number(rivi_vektori.at(3)) or rivi_vektori.at(3) == "on-the-shelf"))
- {
- cout << "Error: the file has an erroneous line" << endl;
- }
- else
- {
- for (int i = 0; i < 3; ++i)
- {
- if (rivi_vektori.at(i) == "")
- {
- cout << "Error: the file has an erroneous line" << endl;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement