hello everyone....i need some help,i am using c++ and vectors, and text files to create a library system and i have a problem.....i used a vector named v1 and i was trying to use an if else to assign a created vectors elements value to another value

example like v[10] is "Storybook5"
i tried this v[10]="storybook3"
and this also v.at(10)="storybook3"

it still will not change,it ll come out Storybook5

i need help.....this is my code.....

void LibraryMember::PrintLoanMem()//this is to print the members on loan,and reduce repetition of members
{
v1.clear();
ifstream loanfile("loan.txt");
string info;
int i;
int j;
int count=0;
int count2=0;
if (loanfile.is_open())
{
while(!loanfile.eof())
{
	getline(loanfile,info);
	v1.push_back(info);
count++;
}
}
count2=count;
v1[3]="";
for(i=0;i<count;i++)
{
for(j=0;j<count2;j++)
{
if (v1[j]==v1[i])
{
v1[j]=="";	
}
}
}
ofstream out("loanMem.txt",ios::app);
size_t size = v1.size();
for (size_t i = 0; i < size; i++) 
{
if(v1.at(i)=="")
{
}
else
out << v1[i] <<endl;
}
}//end function printloan mem
Comments
Times up, learn to use code tags or leave

More specifically, a small piece of code that actually exhibits the behaviour you consider to be a problem.

The code you've given does not appear related to the text in your post in any way.

Indeed, however i have a feeling it may be a similar problem to this....

if (v1[j]==v1[i])
{
v1[j]=="";	
}

What exactly does this do?

I think it's a problem with your understanding of the std::vector class properties.
Before using v[10] you must initialize v[10] vector element. For example, you can declare std::vector<type> v(N) or call v.push_back(something) at least N times or call v.resize(N) where N >= 11.

This article has been dead for over six months. Start a new discussion instead.