Skip to main content
replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
URL Rewriter Bot
URL Rewriter Bot

There is a lot to be said for knowing how to solve problems, but this isn't one of them.

#include <vector> #include <iostream> int main() { std::vector<int> numbers; for (int i = 0; i < 11; i++) { numbers.push_back(i); } for (int i = 0; i < numbers.size(); i++) { std::cout << numbers[i] << ". "; } std::cout << "\n"; } 

UPDATE: As shown above in my other answermy other answer his function contains at least four bugs in 16 lines. That is a bug for every four lines of code. And then there are the problems with the design of the code. For example the size of the array and the array itself should be together. You can't otherwise guarantee that the function works.

Two of the problems in the code (2,4) could be solved by using a struct containing the array pointer and the max_size of the data structure. That way you have to pass the two variables together.

There is a lot to be said for knowing how to solve problems, but this isn't one of them.

#include <vector> #include <iostream> int main() { std::vector<int> numbers; for (int i = 0; i < 11; i++) { numbers.push_back(i); } for (int i = 0; i < numbers.size(); i++) { std::cout << numbers[i] << ". "; } std::cout << "\n"; } 

UPDATE: As shown above in my other answer his function contains at least four bugs in 16 lines. That is a bug for every four lines of code. And then there are the problems with the design of the code. For example the size of the array and the array itself should be together. You can't otherwise guarantee that the function works.

Two of the problems in the code (2,4) could be solved by using a struct containing the array pointer and the max_size of the data structure. That way you have to pass the two variables together.

There is a lot to be said for knowing how to solve problems, but this isn't one of them.

#include <vector> #include <iostream> int main() { std::vector<int> numbers; for (int i = 0; i < 11; i++) { numbers.push_back(i); } for (int i = 0; i < numbers.size(); i++) { std::cout << numbers[i] << ". "; } std::cout << "\n"; } 

UPDATE: As shown above in my other answer his function contains at least four bugs in 16 lines. That is a bug for every four lines of code. And then there are the problems with the design of the code. For example the size of the array and the array itself should be together. You can't otherwise guarantee that the function works.

Two of the problems in the code (2,4) could be solved by using a struct containing the array pointer and the max_size of the data structure. That way you have to pass the two variables together.

update
Source Link
Peter Stuifzand
  • 5.1k
  • 1
  • 26
  • 28

There is a lot to be said for knowing how to solve problems, but this isn't one of them.

#include <vector> #include <iostream> int main() { std::vector<int> numbers; for (int i = 0; i < 11; i++) { numbers.push_back(i); } for (int i = 0; i < numbers.size(); i++) { std::cout << numbers[i] << ". "; } std::cout << "\n"; } 

UPDATE: As shown above in my other answer his function contains at least four bugs in 16 lines. That is a bug for every four lines of code. And then there are the problems with the design of the code. For example the size of the array and the array itself should be together. You can't otherwise guarantee that the function works.

Two of the problems in the code (2,4) could be solved by using a struct containing the array pointer and the max_size of the data structure. That way you have to pass the two variables together.

There is a lot to be said for knowing how to solve problems, but this isn't one of them.

#include <vector> #include <iostream> int main() { std::vector<int> numbers; for (int i = 0; i < 11; i++) { numbers.push_back(i); } for (int i = 0; i < numbers.size(); i++) { std::cout << numbers[i] << ". "; } std::cout << "\n"; } 

There is a lot to be said for knowing how to solve problems, but this isn't one of them.

#include <vector> #include <iostream> int main() { std::vector<int> numbers; for (int i = 0; i < 11; i++) { numbers.push_back(i); } for (int i = 0; i < numbers.size(); i++) { std::cout << numbers[i] << ". "; } std::cout << "\n"; } 

UPDATE: As shown above in my other answer his function contains at least four bugs in 16 lines. That is a bug for every four lines of code. And then there are the problems with the design of the code. For example the size of the array and the array itself should be together. You can't otherwise guarantee that the function works.

Two of the problems in the code (2,4) could be solved by using a struct containing the array pointer and the max_size of the data structure. That way you have to pass the two variables together.

Source Link
Peter Stuifzand
  • 5.1k
  • 1
  • 26
  • 28

There is a lot to be said for knowing how to solve problems, but this isn't one of them.

#include <vector> #include <iostream> int main() { std::vector<int> numbers; for (int i = 0; i < 11; i++) { numbers.push_back(i); } for (int i = 0; i < numbers.size(); i++) { std::cout << numbers[i] << ". "; } std::cout << "\n"; }