Thread: Extract char

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    49

    Extract char

    I have a vector of strings
    Code:
    vector<string> notes;
    Each string is built from a collection of chars.

    I want to extract the first char:

    Code:
    vector<string>::iterator notes_iterator;
    for(notes_iterator=notes.begin(); notes_iterator!=notes.end(); notes_iterator++) 
    {
    	char tempchar=notes_iterator->begin();
    }
    I get the error:
    Code:
    error C2440: 'initializing' : cannot convert from 'std::basic_string<_Elem,_Traits,_Ax>::iterator' to 'char'
            with
            [
                _Elem=char,
                _Traits=std::char_traits<char>,
                _Ax=std::allocator<char>
            ]

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    49
    Found it. Should add an astrix

    Code:
    char tempchar=*notes_iterator->begin();

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It's a vector of std::strings, not char, so you need to do some appropriate action on the std::string object to get the char.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Conversion Char To Char * Problem
    By ltanusaputra in forum Windows Programming
    Replies: 3
    Last Post: 03-01-2008, 02:06 PM
  2. code condensing
    By bcianfrocca in forum C++ Programming
    Replies: 4
    Last Post: 09-07-2005, 09:22 AM
  3. I'm having a problem with data files.
    By OmniMirror in forum C Programming
    Replies: 4
    Last Post: 05-14-2003, 09:40 PM
  4. Passing structures... I can't get it right.
    By j0hnb in forum C Programming
    Replies: 6
    Last Post: 01-26-2003, 11:55 AM
  5. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 01:18 AM