Age Generating Console Program

This is a discussion on Age Generating Console Program within the C++ Programming forums, part of the General Programming Boards category; >>transform ( answ.begin(), answ.end(), answ.begin(), ptr_fun(::tolower) ); The transform is wrong. You are invoking undefined behavior here. You really should ...

  1. #16
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,587
    >>transform ( answ.begin(), answ.end(), answ.begin(), ptr_fun(::tolower) );
    The transform is wrong. You are invoking undefined behavior here.
    You really should be doing

    transform ( answ.begin(), answ.end(), back_inserter(answ), &tolower );

    back_inserter can be found in <iterator>.
    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.

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by Elysia View Post
    >>transform ( answ.begin(), answ.end(), answ.begin(), ptr_fun(::tolower) );
    The transform is wrong. You are invoking undefined behavior here.
    You really should be doing

    transform ( answ.begin(), answ.end(), back_inserter(answ), &tolower );

    back_inserter can be found in <iterator>.
    Eh? A string iterator is an output iterator, so far as I can tell. Also I don't think he wants the lowercased version of his string stuck at the end of his regular string.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  2. Help with console program
    By feso4 in forum C++ Programming
    Replies: 3
    Last Post: 10-22-2006, 11:53 AM
  3. my first windows console program
    By Syneris in forum Windows Programming
    Replies: 3
    Last Post: 04-08-2002, 03:18 PM
  4. DOS program versus DOS console program
    By scromer in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 01-10-2002, 12:42 PM
  5. semaphores using C++ in console program
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 12-20-2001, 11:46 AM

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