Thread: c++ strings

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    29

    c++ strings

    hey,
    I'm trying to do the c++ style strings tutorial on this site but it's not working. Could it be because I'm using Dev c++?

    here's my code:

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    using namespace std;
    
    int main()
    {
    string my_string;
          return 0;
    }
    not realy sure why this won't work. Help would be apreciated, thanks

  2. #2
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    the program itself will not indicate to the user whether it's working or not.
    the program simply declares a variable, then exits. any compiler errors?


    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main()
    {
         string first_name;
         string last_name;
         
         cout << "Enter your first name:  ";
    
         cin >> first_name;
      
         cout << "\n\nEnter your last name:  ";
    
         cin >> last_name;
    
         cout << "\n\nYour full name is:  " <<  first_name << "  " << last_name;
    
         cout << "\n\nYour initials are:  " << first_name[0] << ". " << last_name[0] << ".";
    
         return 0;
    }
    Last edited by The Brain; 07-05-2005 at 07:31 PM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    29
    I just didn't include the right header, thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings Program
    By limergal in forum C++ Programming
    Replies: 4
    Last Post: 12-02-2006, 03:24 PM
  2. Programming using strings
    By jlu0418 in forum C++ Programming
    Replies: 5
    Last Post: 11-26-2006, 08:07 PM
  3. Reading strings input by the user...
    By Cmuppet in forum C Programming
    Replies: 13
    Last Post: 07-21-2004, 06:37 AM
  4. damn strings
    By jmzl666 in forum C Programming
    Replies: 10
    Last Post: 06-24-2002, 02:09 AM
  5. menus and strings
    By garycastillo in forum C Programming
    Replies: 3
    Last Post: 04-29-2002, 11:23 AM