Advertisement
kylemsguy

S12010.cpp

Mar 2nd, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. /*
  2. NOTE: This code segmentation faults. I'm not responsible if it causes
  3. your computer to explode. Kthxbai.
  4. */
  5. #include <iostream>
  6. #include <string>
  7. #include <cmath>
  8. #include <cstdlib>
  9. #include <vector>
  10. #include <sstream>
  11. using namespace std;
  12.  
  13. typedef struct{
  14. string name;
  15. int ram;
  16. int cpu;
  17. int hdd;
  18. }computer;
  19.  
  20. int main(int argc, char *argv[]){
  21. int numComps;
  22. int ram;
  23. int cpu;
  24. int hdd;
  25. vector<computer> computers;
  26.  
  27. cin >> numComps;
  28.  
  29. for(int i = 0; i < numComps; ++i){
  30. string inData;
  31. string tempString;
  32. vector<string> dataVector;
  33. computer tempComp;
  34. stringstream ss;
  35.  
  36. getline(cin, inData);
  37.  
  38. for(int ii = 0; i < inData.size(); ++i){
  39. if(inData[ii] == ' '){
  40. ss >> tempString;
  41. continue;
  42. }
  43. else{
  44. ss << inData[ii];
  45. }
  46. }
  47.  
  48. tempComp.name = dataVector[0];
  49. tempComp.ram = atoi(dataVector[1].c_str());
  50. tempComp.cpu = atoi(dataVector[2].c_str());
  51. tempComp.hdd = atoi(dataVector[3].c_str());
  52.  
  53. computers.push_back(tempComp);
  54.  
  55. }
  56.  
  57. return 0;
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement