Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - The custom function of C language and the problem of reading numbers into arrays
The custom function of C language and the problem of reading numbers into arrays
Int * & amppVec is a reference to int pointer in C++, that is, PVec itself is a reference to a parameter when calling a function, and the type of this parameter is a pointer to an integer. The reason for using a reference is to modify the contents of this pointer in the function. (If you only need to modify the contents of the memory cell pointed by the pointer, you only need to use the pointer type as a formal parameter. )

The Size in int & ampSize is also a reference, pointing to the int type, and its purpose is also to modify the value of the referenced parameter.

Fstream is a file stream type in C++, which can be read and written. You can pass in an object of type fstream, and the purpose of the function is to modify the content of the original parameter, and the reference will not copy the parameter.

For the use and introduction of references, please refer to:

/weiqubo/archive/2009/08/ 10/443 1062 . aspx

If C++ is allowed, it can:

# include & ltiostream & gt

# include & ltfstream & gt

# include & ltvector & gt

# include & lt iterator & gt

# include & lt algorithm & gt

Use namespace std

int main(){

Fstream file ("task. txt");

Vector & ltint & gtivec

copy(istream _ iterator & lt; Int> (file), istream _ iterator & ltint & gt (), back _ inserter(ivec)););

copy(ivec.begin(),ivec.end(),ostream _ iterator & ltint & gt(cout," \ n "));

Returns 0;

}

The purpose of the above program is to read all the contents of task.txt and then output a number per line.

The first address of the array you want can be passed through &; Ivec[0], whose length is ivec.size ().