How can I use vector for entering numbers? I want to enter names, student numbers and student scores and display this information. I used arrays in this way:

#include "stdafx.h"
#include &lt;iostream&gt;
#include &lt;string&gt;
#define size 3
using namespace std;
class student{
public:
    void vrod();
    void dis();
    int stno,score,i,n;
};
void student::vrod(){
cout&lt;&lt;"name=";
cin&gt;&gt;name;
cout&lt;&lt;"stno=";
cin&gt;&gt;stno;
cout&lt;&lt;"score=";
cin&gt;&gt;score;
}
void student::dis(){
    cout&lt;&lt;"name="&lt;&lt;name&lt;&lt;"\n"&lt;&lt;"stno="&lt;&lt;stno&lt;&lt;"\n"&lt;&lt;"score="&lt;&lt;score&lt;&lt;"\n";

}


int main(){
int i, j=0,n,;
string h;

student st[size];
while (j&lt;3){
st[j].vrod();

j++;}
j=0;
while (j&lt;3){
st[j].dis();

j++;}
cin.get();
cin.get();
}


According to recommendation of my friends, I used vector in this way:

#include "stdafx.h"
#include&lt;iostream&gt;
#include&lt;vector&gt;
#include&lt;sstream&gt;
#include&lt;string&gt;
#define n 3
using namespace std;

int main()
{
  int input;
  string names;
  vector&lt;int&gt; stno,score;
  vector&lt;string&gt; name;
  cout&lt;&lt;"Enter the number of inputs: ";

  cout &lt;&lt; "Enter your numbers to be evaluated: " &lt;&lt; endl;
  for(int i=0;i&lt;n;i++){
      cout&lt;&lt;"student No.=";
  cin &gt;&gt; input;
  stno.push_back(input);
  }

 for(int i=0;i&lt;n;i++){
      cout&lt;&lt;"scor=";
  cin &gt;&gt; input;
  score.push_back(input);
  }

 for(int i=0;i&lt;n;i++){
     cout&lt;&lt;"name=";
  cin &gt;&gt; names;
  name.push_back(names);
  }

   for(int i=0;i&lt;stno.size();i++)
       cout&lt;&lt;stno[i];
    for(int i=0;i&lt;score.size();i++)
       cout&lt;&lt;score[i];
    for(int i=0;i&lt;name.size();i++)
       cout&lt;&lt;name[i];

  cin.get();
  cin.get();
}


Do you have any opinion to improve the second code written via vector? Can I save information from one student including student numbers and student scores in one position in vector like arrays? I mean for example if my n is 3, I enter the information of students in three positions like arrays(student st[size];)
Formatting

This is probably the worst formatted piece of code I have seen in a while. It does not matter to the compiler but you are writing in a high level language so that other humans can read it.


Indentation
White Space
one line per declaration
Use meaningful variable and function names (don't shorten them).


Examples:

void student::vrod(){
cout&lt;&lt;"name=";
cin&gt;&gt;name;
cout&lt;&lt;"stno=";
cin&gt;&gt;stno;
cout&lt;&lt;"score=";
cin&gt;&gt;score;
}

// this should be (more like)

void student::vrod()
{
    std::cout &lt;&lt; "name=";
    std::cin &gt;&gt; name;

    std::cout &lt;&lt; "stno=";
    std::cin &gt;&gt; stno;

    std::cout &lt;&lt; "score=";
    std::cin &gt;&gt; score;
}


Declarations. The types of objets are the most important thing in C++. So give each object a name and a type and use a single line for each.

    int stno,score,i,n;

    // That's just lazy;

    int stno;   // Why not studentNumber
    int score;
    int i;
    int n;


Stop Using "using"

using namespace std;


See: Why is “using namespace std” in C++ considered bad practice?

For anything longer than a 10 line program it becomes a curse and is likely to get you into trouble (in a way that is hard to find). So avoid doing it. Also avoid using it in your 10 line programs as that can be habit forming and will make you use it accidently).

Nameing conventions.

It is common convention for user defined types to have an initial capitol letter. This is to make types stand out from objects.

MyThing();  // This is a temporary object that is created.
myThink();  // This is a function call
            //
            // Notice the initial capitol letter allows you
            // to distinguish the two.


Also member variables should be nouns (the names of things, descriptive). While methods should be verbs (actions that are applied to your object). Using longer names will not make the code larger but it will make the code more readable.

class Student
{
    public:
        // Method names are actions that can be applied to
        // the object (avoid names like get/set it breaks encapsulation

        void getInfo(std::istream&amp; str = std::cin);
        void display(std::ostream&amp; str = std::cout);
    private:
        // Member variables should always be private.
        // Any modification of the state of the object
        // should be controlled by a method of the class
        // so that state can be updated consistently.

        // Use meaningful names.
        // Note: These are inside the student class.
        //       So name  =&gt; is a student name
        //          score =&gt; is a student score

        std::string   name;   // You seem to have forgotten this member.
        std::size_t   number;
        int           score;
        // These seem redundant so I am removing them.
        // int           i;
        // int           n;
};


Input and Output operator.

Your functions. vrod() and dis() work fine. But they only accept input/ouput from the standard streams. It would be nice if they could accept input/output from any stream (like a string or a file or a network socket).

You should pass the stream they are going to use as a parameter. You can default it to the stanadrd stream so that if it is not specified then it uses std::cin/std::cout.

class student{
public:
    void vrod(std::istream&amp; in = std::cin);
    void dis(std::ostream&amp; out = std::cout);
};


Then normal input and output is done via operator&lt;&lt; and operator&gt;&gt;. Writting these for your class becomes very simple.

std::ostream&amp; operator&lt;&lt;(std::ostream&amp; s, student const&amp; data)
{
    data.dis(s);
    return s;
}
std::istream&amp; operator&gt;&gt;(std::istream&amp; s, student&amp; data)
{
    data.vrod(s);
    return s;
}


Now you can print your object just like other objects.

std::cin &lt;&lt; st[2];


Overall

The first prgram is better than the second program because of the encapsulation of student. BUT arrays are not very flexable and you should be using std::vector&lt;student&gt; st; ratheer than student st[size];. The ability to resize, lazily construct objects, always know the its size are three definite advantages that vector has over an array.