fork download
  1. #include<iostream>
  2. #include<iomanip>
  3. #include<fstream>
  4. #include<string>
  5. #include<sstream>
  6. #include<vector>
  7.  
  8. using namespace std;
  9.  
  10. struct transaction
  11. {
  12. string item;
  13. int cost;
  14. };
  15.  
  16. int main()
  17. {
  18. transaction buy[100];
  19. transaction sell[100];
  20. int price;
  21. int w, s;
  22. ifstream myfile.open ("messageBoard.txt");
  23. ofstream results.open ("results.txt");
  24. string line;
  25.  
  26. }
  27. myfile >> getline(myfile, buy[w], '\n');
  28. if
  29. if(!myfile)
  30. {
  31. cout<<"Error opening input file"<<endl;
  32. return -1;
  33. }
  34. while(myfile, line)
  35. {
  36. if(line.find("wanted") != string::npos);
  37. {
  38. getline(myfile,buy[w].item);
  39. getline(myfile,price);
  40. stringstream(price) >> buy[w].cost;
  41. }
  42. }
  43. while(myfile, line)
  44. {
  45. if(line.find("for sale") != string::npos);
  46. {
  47. getline(myfile,buy[s].item);
  48. getline(myfile,price);
  49. stringstream(price) >> buy[s].cost;
  50. }
  51. }
  52. for(w=0; w<100; w++)
  53. {
  54. for(s=0; s<100; s++)
  55. {
  56. if(buy[w].item == sell[s].item && buy[w].cost <= sell[s].cost)
  57. if (results.is_open())
  58. {
  59. results << buy[w] << " matches " << sell[s] << "\n";
  60. }
  61. else
  62. cout << "Unable to open output file." << endl;
  63. buy[w] = 0;
  64. sell[s] = 0;
  65. }
  66. }
  67. results.close();
  68. return 0;
  69. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:22:20: error: expected initializer before ‘.’ token
     ifstream myfile.open ("messageBoard.txt");
                    ^
prog.cpp:23:21: error: expected initializer before ‘.’ token
     ofstream results.open ("results.txt");
                     ^
prog.cpp:18:17: warning: unused variable ‘buy’ [-Wunused-variable]
     transaction buy[100];
                 ^
prog.cpp:19:17: warning: unused variable ‘sell’ [-Wunused-variable]
     transaction sell[100];
                 ^
prog.cpp:20:9: warning: unused variable ‘price’ [-Wunused-variable]
     int price;
         ^
prog.cpp:21:9: warning: unused variable ‘w’ [-Wunused-variable]
     int w, s;
         ^
prog.cpp:21:12: warning: unused variable ‘s’ [-Wunused-variable]
     int w, s;
            ^
prog.cpp: At global scope:
prog.cpp:27:4: error: ‘myfile’ does not name a type
    myfile >> getline(myfile, buy[w], '\n');
    ^
prog.cpp:28:9: error: expected unqualified-id before ‘if’
         if
         ^
prog.cpp:34:9: error: expected unqualified-id before ‘while’
         while(myfile, line)
         ^
stdout
Standard output is empty