Answer to Question #310676 in C++ for rehman

Question #310676

write a programe that reads number from a file named "data.txt" and tell wheather all number in that file are unique or not ? i


1
Expert's answer
2022-03-13T06:03:28-0400
#include <iostream>
#include <fstream>
#include <set>
using namespace std;


int main() {
    ifstream ifs("data.txt");
    set<int> S;
    int x;


    while (!ifs.eof()) {
        ifs >> x;
        auto it = S.find(x);
        if (it == S.end()) {
            cout << "Not unique";
            return 0;
        }
    }


    cout << "All numbers are unique";
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment