|
-
Aug 1st, 2001, 01:37 PM
#1
Thread Starter
New Member
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?
"go masturbate with a cheese grater"
-
Aug 1st, 2001, 02:02 PM
#2
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.
-
Aug 1st, 2001, 05:02 PM
#3
Monday Morning Lunatic
Nooo....don't do that to your program... 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;
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Aug 1st, 2001, 06:19 PM
#4
Its just for my "INT"s and "DWORD"s =).
Z.
-
Aug 1st, 2001, 06:25 PM
#5
Addicted Member
why shouldn't you include <windows.h>
-
Aug 1st, 2001, 07:45 PM
#6
It will bloat the application.
Z.
-
Aug 1st, 2001, 11:57 PM
#7
Addicted Member
how much will it bloat it?
-
Aug 2nd, 2001, 03:48 AM
#8
Thread Starter
New Member
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?
"go masturbate with a cheese grater"
-
Aug 2nd, 2001, 09:55 AM
#9
transcendental analytic
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
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 2nd, 2001, 10:26 AM
#10
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|