Thread: string arrays

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    80

    string arrays

    hi. in C i can use gets function to create a string array but in c++
    how can i do this?
    for instance:
    Code:
    #include <iostream>
    #include <string>
    
    main() {
    string *sentence;
    
    cin>>sentence;
    
    cout<<sentence;
    }
    is that true?

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    not quite.
    Code:
    #include <iostream>
    #include <string>
    
    using namespace std; // using new style headers everything is in namespace std
    
    int main()
    {
    string sentence; //u need object not pointer
    cin>>sentence;
    cout<<sentence<<endl;
    return 0;
    }
    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

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. String Class
    By BKurosawa in forum C++ Programming
    Replies: 117
    Last Post: 08-09-2007, 01:02 AM
  3. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  4. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  5. string handling
    By lessrain in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 07:36 PM