Results 1 to 10 of 10

Thread: c++ vectors

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    6

    Question 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"

  2. #2
    Zaei
    Guest
    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.

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  4. #4
    Zaei
    Guest
    Its just for my "INT"s and "DWORD"s =).

    Z.

  5. #5
    Addicted Member
    Join Date
    Jul 2000
    Location
    California
    Posts
    154
    why shouldn't you include <windows.h>
    VB-World addict!

    All spelling errors are undocumented words!
    http://www.bells.f2s.com

  6. #6
    Zaei
    Guest
    It will bloat the application.

    Z.

  7. #7
    Addicted Member
    Join Date
    Jul 2000
    Location
    California
    Posts
    154
    how much will it bloat it?
    VB-World addict!

    All spelling errors are undocumented words!
    http://www.bells.f2s.com

  8. #8

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    6

    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"

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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.

  10. #10
    Zaei
    Guest
    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
  •  



Click Here to Expand Forum to Full Width