Having trouble getting this code to run in VS2012, what am I missing #include <i
ID: 3663884 • Letter: H
Question
Having trouble getting this code to run in VS2012, what am I missing
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
int myints[] = {234,0,-2,65535,256,-255};
//Initializing container
vector<int> fifth (myints, myints + sizeof(myints) / sizeof(int) );
cout << "Initial Container: ";
for (vector<int>::iterator it = fifth.begin(); it != fifth.end(); ++it)
cout << ' ' << *it;
cout << ' ';
//Adding values to container
cout << " Container after adding -3 -2 1 and 5: ";
for (vector<int>::iterator it = fifth.begin(); it != fifth.end(); ++it)
{
*it = *it -3;
*it = *it -2;
*it = *it +1;
*it = *it +5;
cout << ' ' << *it;
}
int startIndex=0;
int max,min,maxIndex,minIndex;
//Calculate Max and Min val and min ,max index
for (vector<int>::iterator it = fifth.begin(); it != fifth.end(); ++it)
{
if(startIndex==0)
{
max =*it;
min =*it;
maxIndex = startIndex;
minIndex = startIndex;
}
else{
if(max <*it)
{
max = *it;
maxIndex= startIndex;
}
if(*it < min)
{
min = *it;
minIndex = startIndex;
}
}
startIndex++;
}
cout<<" Min value in container:"<<min<<endl;
cout<<"Max value in container:"<<max<<endl;
//Erase Max and Min values from containerby min and max index
fifth.erase(fifth.begin()+(maxIndex));
fifth.erase(fifth.begin()+(minIndex-1));
cout << " Container after removed min and max values: ";
for (vector<int>::iterator it = fifth.begin(); it != fifth.end(); ++it)
cout << ' ' << *it;
cout<<endl;
return 0;
}
Explanation / Answer
I ran this program in VS2012 and VS2015 ..follow the below steps to createrun this below C++ program:
Step 1: Create New Project from file Menu
Step 2: Select Templates->Visual C++ -> Win32 Console Application
Step 3: Here you can give the name of the project as you like..like example
Once enter the name press okay
Step 4: Then Win32 Application Wizard Window will appear then press next
Step 5: In Application Setting select only console application option unselecte all other options then press Finsih Button.
Step 6: Then copy this code in .cpp window by including #include "stdax.h" file in main function you can copy this code and run this code by pressing Ctrl+F7 and build F7 ..
Step 7: then it will give the successfully build
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.