making a list of names

i am trying to write a program that that accept list of names in vector, write them out, remove a name, sort the list save it to file. wondering if i could get help.
here is my code.
/*
void addName()
{

const int SIZE = 30, SIZE1 = 60;
char f_namn[SIZE] = "";
char last_namn[SIZE]="";
char full_name[SIZE1]="";

/* en vektor that can hold full namn*
vector<string> names;
/* en sentinel used to end input*
string sentinel= "end";
int counter=0;

cout<<" ******************Namelist*****************\n";
/* ask after first name*/
cout << " input first name and stop input with'end': ";
cin>>for_namn;
/* controll first name before last name input*/
while (for_namn != sentinel)
{
/* input last name*/
cout << " input lastname: ";
cin>>last_name;

/* make two name inputs to full name*/
lägger kopia av efternamn sist i fullnamn *
strcat(full_name,last_name);
strcat(full_name," ");
strcat(full_name,f_namn);

names.push_back(full_name);

/* empty full_name to be able to take new full namn*
*full_name = NULL;
/* Push fullname onto vector*/

cout << " input first name or end input with 'end': ";
cin>>f_namn;
}

/* skapa en file att lagrar vektor*
fstream inout;
inout.open("list.txt",ios::out | ios::app);

/* använder en for loop att lagrar vektor i filen*
for ( int i=counter; i < names.size(); i++ )
{
inout<< names[i] << endl;
}
inout.close();

system("pause");
}



//---------------------------------------------------------------------------------------------------
void skrivnamnlista()
{
system("cls");
const int size = 20;
string namevektor2[size];

cout<<" *****NAMNLISTA*****"<<endl;
/* ifstream construktor opend the file*
ifstream innamnlist;
innamnlist.open("list.txt", ios::in);

/*exit program if ifstream could not open file*
if(innamnlist.is_open())
{
string namevektor2[size];
int row= 0;

while (getline(innamnlist, namevektor2[row]))
{
cout<<namevektor2[row]<<endl;
row++;
}
}
innamnlist.close();


system("pause");

}
/***********************************************************************************************************************************************
void sort()
{

const int size = 10;
string vektor[size];


system("cls");
/* ifstream construktor opend the file*
ifstream innamnlist;
innamnlist.open("list.txt", ios::in);

cout<<" *****NAMNLISTA*****"<<endl;
/*exit program if ifstream could not open file*
if(!innamnlist)
{
cerr << " filen inte kan öppna"<<endl;
exit(1);
}/*end if*

string s;
int row= 0;

while (getline(innamnlist, s))
{
if(row<size)
vektor[row++] = s ;
}
for(int pass=0; pass < size-1; pass++)
for(int i=0; i<size-1;i++)
if(vektor[i]>vektor[i+1])
{
string temp = vektor[i];
vektor[i] = vektor[i+1];
vektor[i+1] = temp;
}
for(int i=0; i<size; i++)
{
cout<<vektor[i]<<endl;
}
innamnlist.close();
system("pause");
}
/***************************************************************************************************
void sok()
{
system("cls");
const int SIZE = 20;
string namevektor2[SIZE];
string searchnamn;
bool found = false;
vector<string> listnamn;

cout<<" *****NAMNLISTA*****"<<endl;

/* ifstream construktor opend the file*
ifstream innamnlist;
innamnlist.open("list.txt", ios::in);

/*exit program if ifstream could not open file*
if(innamnlist.is_open())
{

int row= 0;

while (getline(innamnlist, namevektor2[row]))
{
listnamn.push_back(namevektor2[row]);
row++;
}
}
cout<<" vilket namn Söka du efter: ";
cin.get();
getline(cin,searchnamn);
cout<<endl;
// sök_i_listan(namevektor2,searchnamn,size);

for(int i=0;i<listnamn.size(); i++)
if(searchnamn == listnamn[i])
{ found = true;
}
if(found== true)
cout<<searchnamn<<" finns i namnlista\n"<<endl;
else
cout<<searchnamn<<" saknas i namnlista"<<endl;

system("pause");

}
Last edited on
use [code] tags and proper indentation.
state your problems exactly.
try to omit the irrelevant parts of your code, or provide a simplified version of it which has the same problem, if you can.
we're busy(/lazy) people..
Last edited on

thanks hamsterman
here is my forst code. we can start from there.
i am suppose to write a code that ask user to input names which is push onto a vector.
this vector vill be read by other function as
void writeoutnames();
void remove name();
and son on.
but i think its better we start with the first option which is to accept input from user and put it in vector.
thanks for your patience.



void addName()
{
// variable for name input
const int SIZE = 30, SIZE1 = 60;
char f_namn[SIZE] = "";
char last_namn[SIZE]="";
char full_name[SIZE1]="";

/* en vektor that can hold full namn*
vector<string> names;

/* en sentinel used to end input*
string sentinel= "end";
int counter=0;

cout<<" ******************Namelist*****************\n";

/* ask after first name*/
cout << " input first name and stop input with'end': ";
cin>>f_namn;

/* controll first name before last name input*/

while (for_namn != sentinel)
{

/* input last name*/
cout << " input lastname: ";
cin>>last_name;


strcat(full_name,last_name);
strcat(full_name," ");
strcat(full_name,f_namn);

names.push_back(full_name);

/* empty full_name to be able to take new full namn*

*full_name = NULL;


cout << " input first name or end input with 'end': ";
cin>>f_namn;

/* skapa en file att lagrar vektor*

fstream inout;
inout.open("list.txt",ios::out | ios::app);

/* use for loop to save vektor i filen*
for ( int i=counter; i < names.size(); i++ )
{
inout<< names[i] << endl;
}
inout.close();

system("pause");
}

}
Topic archived. No new replies allowed.