473,383 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

problem storing a string from a file

4
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.getEmpPass() != 0 )
{ // the excutions halts here !!!

tempVarData1 = employee.getEmpPass();
tempVarData2 = employee.getEmpPriv();
tempVarData3 = employee.getEmpUserName();

if (( tempVarData1 == e_pass2 )&&(tempVarData3 == 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.getEmpUserName(); to the string variable
Apr 18 '07 #1
3 1272
nmadct
83 Expert
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.
Apr 18 '07 #2
fathi
4
this is the function definition inside the class.cpp:

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

void empclass::setEmpUserName ( string e_userNameString )
{
//copy at most 15 characters from string to e_userUame
const char *userNameValue = e_userNameString.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::getEmpUserName()
{
return e_userName;

}//end funcion get username

void empclass::setEmpUserName ( string e_userNameString )
{
e_userName = e_userNameString;
}


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
Apr 18 '07 #3
Savage
1,764 Expert 1GB
Hi,

how have you declared getEmpPass( ) function?


Savage
Apr 18 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: SB | last post by:
Hello. I have an input file which is laid out in the following manner... Name Day 1 am time 1 am time 2 appointment pm time 1 pm time 2 appointment Day 2
2
by: Ram Laxman | last post by:
Hi all, I have written the following code: /* strtok example */ #include <stdio.h> #include <string.h> static const char * const resultFileName = "param.txt";
1
by: Andrew | last post by:
Hey all, Working on revamping our Intranet here and making use of the LDPA, Active Directory, Directory Services, etc. that .Net provides. I am still fairly new on this subject, so the problem...
6
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any...
6
by: (PeteCresswell) | last post by:
User wants to go this route instead of storing pointers in the DB and the documents outside. Only time I tried it was with only MS Word docs - and that was a loooong time ago - and it seemed to...
0
by: nass | last post by:
hello everyone and happy new year. i am not sure how to tackle this problem or where is originates from so i am writing here in hope that if you can not help you can at least point me in a...
1
by: CodeMonkey | last post by:
We have quite a few datasets that have been designed through the IDE. In our application, we generate a connection string to the server based on what the user configures the application for. The...
6
by: efrenba | last post by:
Hi, I came from delphi world and now I'm doing my first steps in C++. I'm using C++builder because its ide is like delphi although I'm trying to avoid the vcl. I need to insert new features...
1
by: saytri | last post by:
I have a problem with this code. I'm, doing a quiz, and the questions are stored in a binary file. My problem is how am i going to compare the answers entered by the user to the correct answers. The...
5
by: zehra.mb | last post by:
Hi, I had written application for storing employee data in binary file and reading those data from binary file and display it in C language. But I face some issue with writing data to binary file....
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.