Codeforces Round 1133 (Div. 1, Div. 2) is coming soon! Register here. ×

ThE_aLpHaBeAt's blog

By ThE_aLpHaBeAt, 14 years ago, In English

This is my code... they view error on vector book(5), Why?

#include<iostream>
using namespace std;
struct letter
{
  string name;
  int age;       
};
vector<letter> book (5);

int main()
{
 int n,i;
 cin>>n;
 while (book.size()<n-1) 
 {
  book.resize(book.size()++);      
 }  
 for (i=0;i<n;i++)
 {
  cin>>book[i].name;
  cin>>book[i].age;    
 }
 cout<<"Information Added!!!\n";
}

  • Vote: I like it
  • -14
  • Vote: I do not like it

»
14 years ago, hide # |
← Rev. 2  
Vote: I like it +5 Vote: I do not like it

book.resize(book.size()++); you can't call ++, book.size() is not "L-value", it is not a reference. should be book.resize(book.size()+ 1); also insdead of while ... you can call book.resize(n);

»
14 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

may be problem on struct? :(

»
14 years ago, hide # |
← Rev. 5  
Vote: I like it +11 Vote: I do not like it

I think you forgot to include vector.

»
14 years ago, hide # |
 
Vote: I like it +5 Vote: I do not like it

Ooo, I'm Understand! That need (#include).....