Advertisement
Mini4dayz

TextFile Issues

Jan 24th, 2025
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | Source Code | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <vector>
  4. #include <string>
  5.  
  6. int main() {
  7. std::vector<int> Array = { 1, 2, 4, 8, 1, 2, 3, 4, 5 };
  8.  
  9. // Open the file and read values
  10. std::ifstream inputFile("1_file.txt");
  11. if (!inputFile) {
  12. std::cerr << "Error opening file!" << std::endl;
  13. return 1;
  14. }
  15.  
  16. int value;
  17. while (inputFile >> value) {
  18. Array.push_back(value);
  19. }
  20.  
  21. inputFile.close();
  22. std::cout << "Updated Array: ";
  23. for (int num : Array) {
  24. std::cout << num << " ";
  25. }
  26. std::cout << std::endl;
  27.  
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement