How can I read integer by ifstream from a file
2 3 -5 9 -6
Besides, how can I read the negative sign also?

Thanks everyone!!

just use stream's >> operator on an integer, it will convert negative sign for you to make the value of the integer negative.

ifstream in("file.txt");
int n;
in >> n;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.