Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. // g++ p1.cpp -o p1
  2. // ./p1
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include <typeinfo>
  7. #include <cstdio>
  8. #include <iostream>
  9. #include <memory>
  10. #include <stdexcept>
  11. #include <string>
  12. #include <array>
  13. #include <cstring>
  14. #include <fstream>
  15.  
  16. using namespace std;
  17.  
  18. int main(){
  19.  
  20.  
  21. for(int i=1; i<5; i++){
  22.  
  23. }
  24.  
  25.  
  26. echo("DONE");
  27. return 0;
  28. }
  29.  
  30. /////////////////////////////////// LIBRARY ///////////////////////////////////////
  31.  
  32. // functions RB
  33.  
  34. void set(string pin, string val){
  35. system("gpio mode "+pin+" out");
  36. system("gpio write "+pin+" "+val);
  37. }
  38. string get(string pin){
  39. string a0 = run("gpio read "+pin);
  40. string a = a0.substr(0,a0.size()-1);
  41. return a;
  42. }
  43.  
  44. // functions OGOLNE
  45.  
  46. void typeVar(string var){
  47. cout << var + ": " + typeid(var).name() << endl;
  48. }
  49. void echo(string s){
  50. cout << s << endl;
  51. }
  52. // std:: -- usunalem przed deklaracją
  53. string run(const std::string& command) {
  54. system((command + " > t.txt").c_str());
  55. std::ifstream ifs("t.txt");
  56. std::string ret{ std::istreambuf_iterator<char>(ifs), std::istreambuf_iterator<char>() };
  57. ifs.close();
  58. if (std::remove("t.txt") != 0) {
  59. perror("Error deleting temporary file");
  60. }
  61. return ret;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement