Extract char

This is a discussion on Extract char within the C++ Programming forums, part of the General Programming Boards category; I have a vector of strings Code: vector<string> notes; Each string is built from a collection of chars. I want ...

  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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,452
    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, 01: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, 10:55 AM
  5. String sorthing, file opening and saving.
    By j0hnb in forum C Programming
    Replies: 9
    Last Post: 01-23-2003, 12:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21