problem storing a string from a file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fathi
    New Member
    • Apr 2007
    • 4

    problem storing a string from a file

    hello guys, i've worked with C, Java, VB and now C++ but i never knew how to deal with strings so a little bit of help will be so appreciated. it is infact a login code. here is the problem:

    //displays all records
    while (inStaff && !inStaff.eof() ) {

    ->problem if ( employee.getEmp Pass() != 0 )
    { // the excutions halts here !!!

    tempVarData1 = employee.getEmp Pass();
    tempVarData2 = employee.getEmp Priv();
    tempVarData3 = employee.getEmp UserName();

    if (( tempVarData1 == e_pass2 )&&(tempVarData 3 == e_username))
    { cout<<"you are now logged in";
    showMenu (tempVarData2);
    }
    else
    {
    cout<<"sorry incorrect password";
    }
    somehow i got it to run once but something was wrong with assigning the string function tempVarData3 = employee.getEmp UserName(); to the string variable
  • nmadct
    Recognized Expert New Member
    • Jan 2007
    • 83

    #2
    What kind of message do you get when execution halts? And how do you know that it's happening right there? Also, it would help if you showed us the declarations for your variables so we know their types.

    Comment

    • fathi
      New Member
      • Apr 2007
      • 4

      #3
      this is the function definition inside the class.cpp:

      string empclass::getEm pUserName()
      {
      return e_userName;
      }//end funcion get username

      void empclass::setEm pUserName ( string e_userNameStrin g )
      {
      //copy at most 15 characters from string to e_userUame
      const char *userNameValue = e_userNameStrin g.data();
      int length = strlen ( userNameValue );
      length = ( length <15 ? length : 14 );
      strncpy ( e_userName, userNameValue, length );

      //append null character to e_username
      e_userName [length] = '\0';

      }//end function set username

      Due to some other errors i changed it to this:

      //get username value
      string empclass::getEm pUserName()
      {
      return e_userName;

      }//end funcion get username

      void empclass::setEm pUserName ( string e_userNameStrin g )
      {
      e_userName = e_userNameStrin g;
      }


      i declared the variables locally inside the main function like this:

      int e_pass2;
      int tempVarData1, tempVarData2;
      string tempVarData3;
      string e_username;


      i declared the variables in the class as private... as following:

      int e_pass;
      string e_userName;
      /////////////////////////////////////////////////////////////////////////////////////////////////////
      i know that the execution stops there bcus if i place any "cout" after that condition statement it wont display. by the way there is no error msg wat happens is the program prompts for the username and password and stops as soon as i key them in.

      thank you

      Comment

      • Savage
        Recognized Expert Top Contributor
        • Feb 2007
        • 1759

        #4
        Hi,

        how have you declared getEmpPass( ) function?


        Savage

        Comment

        Working...