Advertisement
Transformator

Untitled

May 23rd, 2015
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <fstream>
  4. #include <string>
  5. #include <sstream>
  6.  
  7. using namespace std;
  8.  
  9. class scht {
  10.     private:
  11.         static vector <string[]> friends;
  12.         static string privatekey;
  13.         static string publickey;
  14.     public:
  15.         static string getFriend(int);
  16.         static void addFriend(string, string);
  17.         static void loadFriend(string, string);
  18.         void write(string, string, int);
  19.         scht();
  20.         ~scht();
  21.         string ciper(string);
  22. };
  23.  
  24. string scht::getFriend(int index) { return (string[])friends.at(index); }
  25.  
  26. void scht::addFriend(string name, string publickey) {}
  27.  
  28. string scht::ciper(string toCiper) {
  29.     return toCiper; // do later more
  30. }
  31.  
  32. void scht::loadFriend(string name, string pubickey) {
  33.     friends.push_back({name, publickey});
  34. }
  35.  
  36. void scht::write(string text, string title, int id) {
  37.     string contact[2] = getFriend(id);
  38.  
  39.     string cipertext = ciper(text);
  40.     string cipertitle = ciper(title);
  41.  
  42.     // BROADCAST
  43. }
  44.  
  45. scht::scht() {
  46.     ifstream friendsFile;
  47.     string line;
  48.     string arr[2];
  49.  
  50.     friendsFile.open("friends.csv", ios::in);
  51.  
  52.     if(friendsFile.is_open()) {
  53.         while(getline(friendsFile, line)) {
  54.             try {
  55.                 for (int i=0; i<line.length(); i++)
  56.                 {
  57.                 if (line[i] == ';')
  58.                 line[i] = ' ';
  59.                 }
  60.  
  61.                 vector<string> array;
  62.                 stringstream ss(line);
  63.                 string temp;
  64.                 while (ss >> temp)
  65.                 array.push_back(temp);
  66.                 if(array.size() != 2)
  67.                     throw(1);
  68.                 loadFriend(array.at(0), array.at(1));
  69.             } catch(...) {
  70.                 throw("[ERROR] to much arguments in one line. please check the 'friends.csv' file!");
  71.             }
  72.         }
  73.     }
  74.  
  75.     friendsFile.close();
  76. }
  77.  
  78. scht::~scht() { cout << endl << "bye bye" << endl; }
  79.  
  80. int main() {
  81.     scht prog;
  82.  
  83.  
  84.     return 0;
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement