I need help an error in my code. stdafx.h header is causing me to get errors. //
ID: 3637866 • Letter: I
Question
I need help an error in my code. stdafx.h header is causing me to get errors. // testrun.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <vector> #include <algorithm> using namespace std; // declaration and implementation for function to print values in a vector //template <typename T> void write_vector(const vector<int> &vect) { // loop from 0 to last element and print each for (unsigned int i = 0; i < vect.size(); i++) cout << vect[i] << " "; cout << endl; } //template <typename T> void rev_vector(vector<int>& vect) { // declare a temp vector to store the new reversed vector vector<int> tempVect; //copy vector starting from the end in a new vector for(int i = (vect.size()-1); i>=0; i--){ tempVect.push_back(vect[i]); } vect.clear(); // copies temp vector back into the origanl vector for(int j = 0; j< tempVect.size();j++){ vect.push_back(tempVect[j]); } } int _tmain(int argc, _TCHAR* argv[]) { vector<int> intvect; int temp; // loop for three sets of input for (int num = 0; num < 3; num++) { cout << "Enter 5 integer values" << endl; // add logic to add values to intvect for (int i = 0; i < 5; i++) { cin >> temp; intvect.push_back(temp); } // add call to function to print vector values write_vector(intvect); //reverse vector rev_vector(intvect); // add call to function to print vector values (now reversed) cout<<"reversed: "; write_vector(intvect); intvect.clear(); } cout << endl << "done" << endl; return 0; } I need help an error in my code. stdafx.h header is causing me to get errors. // testrun.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <vector> #include <algorithm> using namespace std; // declaration and implementation for function to print values in a vector //template <typename T> void write_vector(const vector<int> &vect) { // loop from 0 to last element and print each for (unsigned int i = 0; i < vect.size(); i++) cout << vect[i] << " "; cout << endl; } //template <typename T> void rev_vector(vector<int>& vect) { // declare a temp vector to store the new reversed vector vector<int> tempVect; //copy vector starting from the end in a new vector for(int i = (vect.size()-1); i>=0; i--){ tempVect.push_back(vect[i]); } vect.clear(); // copies temp vector back into the origanl vector for(int j = 0; j< tempVect.size();j++){ vect.push_back(tempVect[j]); } } int _tmain(int argc, _TCHAR* argv[]) { vector<int> intvect; int temp; // loop for three sets of input for (int num = 0; num < 3; num++) { cout << "Enter 5 integer values" << endl; // add logic to add values to intvect for (int i = 0; i < 5; i++) { cin >> temp; intvect.push_back(temp); } // add call to function to print vector values write_vector(intvect); //reverse vector rev_vector(intvect); // add call to function to print vector values (now reversed) cout<<"reversed: "; write_vector(intvect); intvect.clear(); } cout << endl << "done" << endl; return 0; }Explanation / Answer
The stdafx.h is not needed, make sure if you are using visual studio, you select a "Empty Project". and make _tmain the standard C++ main function. One last note j in rev_vector should also be an unsigned type, usually you are suppose to use "size_t" instead, but if you didn't get to the in class, that's fine.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.