Thread: Code errror on vector string

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    7

    Code errror on vector string

    HI,

    I took this code from the example given by the expert...
    but it seem has error...
    its error is
    Error E2451 test9.cpp 11: Undefined symbol 'vector' in function main()
    Error E2294 test9.cpp 17: Structure required on left side of . or .* in function main()

    the point is i want to copy only string "A" from the whole string if only it detect "object Class" from the string...

    Code:
    #include <string>
    #include <string.h>
    #include <stdio.h> 
    #include <stdlib.h> 
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    int main()
        {
        vector<int> v( 5, 1 );// --> error
        string str;
        str = "object Class A";
        int v;
        for( int i = 0; i < 20; i++ ) {
        cout << str << i << " is " << v.at(i) << endl;
        
    
         ofstream myfile ("example.txt",ios::app); //open file
          if (myfile.is_open())
         
        {
         if (i <= 12)                  //for every (ch <=12 ) will be store
         {myfile<<v.at(i);}
         }
    
         myfile.close();
    
        }
      
    return 0;
        }
    so i need the loc indec to be just at the end of "object Class" so i can store string "A" into file....
    what is the problem can u help me guys?

  2. #2
    System.out.println("");
    Join Date
    Jan 2005
    Posts
    84
    I really didn't check the logic, but it compiles and runs if you get rid of:

    Code:
    int v;
    You don't use it. v is already declared as a vector.

    You need to include the vector header since you are using it.

    Code:
    #include <vector>
    Also you don't need string.h since you are already including string (always include string and not string.h (it's old)). I also don't think you need these header files:

    Code:
    #include <stdio.h> 
    #include <stdlib.h>
    Last edited by Loctan; 12-28-2006 at 11:34 PM.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    if (i <= 12) //for every (ch <=12 ) will be store
    i is not defined here...
    you also not initialized vector with something usefull, why do you want to print it?
    In the loop you print str on every iteration - but it is not changed... So Why?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    Registered User
    Join Date
    Oct 2006
    Posts
    7
    SOLVED

    Thank you loctan and vart, thanks a lot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 08:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  3. Obfuscated Code Contest: The Results
    By Stack Overflow in forum Contests Board
    Replies: 29
    Last Post: 02-18-2005, 05:39 PM
  4. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM