Thread: About string input in C++

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    71

    About string input in C++

    Code:
    #include <cstdio>
    #include <cstdlib>
    
    
    int main( void )
    {
    
         char Buffer[100];
         char* Name= new char[100];
         int number;
         
         
         printf( "Please Input A Number: " );
         scanf( "%s", Name );
         
         
         sprintf( Buffer, "%s", Name );
         printf( "Hi %s!!", Buffer );
         
         
         rewind( stdin );
         rewind( stdout );
         
         delete [] Name;
         
         return(EXIT_SUCCESS);
    }
    The sprintf() function.....is there a C++ equivalent to it? That also handles std::string?
    Name: Eric Lesnar
    Learning: C/C++, SDL, WinAPI, OpenGL, and Python
    Compiler: Dev-C++ 4.9.0
    Current Game Project: Acoznict

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    look up stringstreams in your helpfiles/text book. Might ( should) be in the faq also.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    King of the Internet Fahrenheit's Avatar
    Join Date
    Oct 2001
    Posts
    128
    Why are you rewinding stdin and stdout?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Replies: 14
    Last Post: 01-18-2008, 04:14 PM
  3. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  4. can anyone see anything wrong with this code
    By occ0708 in forum C++ Programming
    Replies: 6
    Last Post: 12-07-2004, 12:47 PM
  5. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM