-
c++ vectors
i am trying to develop a program where you enter a bunch of encrypted letters and the non encrypted one comes out
for instance here is what i have so far (this is in vc++ 6.0, which i currently do use, i used to program on teh PC version of metrowerks codewarrior 6.0)
#include <iostream.h>
#include <iomanip.h>
#include <fstream.h>
char code;
int main()
{
cout << "Decrypter" << endl;
cout << "programmed in c++" << endl;
cout <<"------------------------------------------" << endl;
cout <<"Please Enter Encrypted code" << endl << endl;
cin >> code;
if(cheatcode == '*_#L1Z')
{
cout << "big" << endl;
}
return 0;
}
this is what i have so far, but i am trying to use vectors, so i can search for encryptod letters but i don't have <vector.h> or i can't use apvector.h...why won't it let me use vectors?
-
Its not actually called <vecotr.h>:
Code:
#include <windows.h>
#include <vector> // no ".h"
#include <iostream.h>
INT main()
{
std::vector<INT> lotsaints;
lotasints.push_back(25);
lotsaints.push_back(10);
for(INT i = 0; i < lotsaints.size(); ++i)
cout << lotsaints[i] << endl;
return 0;
}
Z.
-
Nooo....don't do that to your program... :eek: Poor program, including windows.h unnecessarily like that :(
Code:
#include <vector> // no ".h"
#include <iostream> // No ".h" on this either
int main() { // This should be int always
std::vector<int> lotsaints;
lotasints.push_back(25);
lotsaints.push_back(10);
for(int i = 0; i < lotsaints.size(); ++i)
std::cout << lotsaints[i] << endl;
return 0;
}
-
Its just for my "INT"s and "DWORD"s =).
Z.
-
why shouldn't you include <windows.h>
-
It will bloat the application.
Z.
-
how much will it bloat it?
-
again!
thats my code (below) -- the program gives me 3 errors -- i dont understand the <vector> what is its syntax? push_back is the array definer? is there a way i can write a pre-written header? apvector?
#include <iostream>
#include <iomanip.h>
#include <windows.h>
#include <fstream.h>
#include <vector>
char code;
int main()
{
std::vector<int> code;
code.push_back(30);
code.push_back(15);
cout << "simple decrypter" << endl;
cout << "programmed in c++" << endl;
cout <<"------------------------------------------" << endl;
cout <<"Please Enter Encrypted code" << endl << endl;
std::cin >> code;
if(code == '*_#L1Z *_Am%% ^@)hx')
{
std::cout << "bigdaddy" << endl;
}
return 0;
}
C:\Program Files\Metrowerks\CodeWarrior\mahmoud\ec\main.cpp(21) : error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::vector<int,class std::allocator<int> >' (or there is no acceptable conversion)
C:\Program Files\Metrowerks\CodeWarrior\mahmoud\ec\main.cpp(23) : error C2015: too many characters in constant
C:\Program Files\Metrowerks\CodeWarrior\mahmoud\ec\main.cpp(23) : error C2678: binary '==' : no operator defined which takes a left-hand operand of type 'class std::vector<int,class std::allocator<int> >' (or there is no acceptable conversion)
Error executing cl.exe.
someone help?
-
It's hard to follow what youre trying to do. the first error occurs because you shouldn't have std:: in front of cin
in the second, one char only should be specified using ' ', otherways you can use " " to specify a string of chars
the third occurs because you can't compare a vector of ints with anything
-
The function "std::vector::push_back()", takes a parameter of the type defined in the template (in your case "INT"). It automatically resizes the vector, and adds the parameter as the last element.
Instead of "cin", look at the getline() function. Define "code" as "char code[64]", and only allow 63 chars as the max input. Use the "strcmp()" function to compare the two strings, instead of "==" (youll get really wierd logic errors, otherwise).
Z.