why does this function crash

This is a discussion on why does this function crash within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> using namespace std; int main () { string dt[3]; string stuff[3]; stuff[1] = "Username: "; stuff[2] = ...

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    43

    why does this function crash

    Code:
    #include <iostream>
    
    using namespace std;
    
    int main ()
    {
        string dt[3];
        string stuff[3];
        stuff[1] = "Username: ";
        stuff[2] = "Password: ";
        stuff[3] = "Confirm Password: ";
                 
        for(int x = 0; x < 3; x++)
        {
        cout<<stuff[x]<<"\n";
        getline(cin, dt[x]);
        }
        
        cin.get();
    }
    nvm, array wasnt big enough
    Last edited by Mythic Fr0st; 01-17-2007 at 02:29 AM.

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    indexes of the array go from 0 to 2 not from 1 to 3
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 06:18 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM

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