- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Read integers from a text file with C++ ifstream
Here is an example of Read integers from a text file with C++ ifstream.
Example
#include <fstream> #include<iostream> using namespace std; int main() { //initialie the array size int arr[30]; ifstream is("a.txt"); int cnt= 0; int x; // check that array is not already full while (cnt < arr[30] && is >> x) // and read integer from file arr[cnt++] = x; // print the integers stored in the array cout<<"The integers are:"<<"\n"; for (int i = 0; i < cnt; i++) { cout << arr[i] <<' '; } //close the file is.close(); }
Output
The integers are: 1 2 3 4 5 6 7
- Related Articles
- Read Data from a Text File using C++
- How to read a text file with C++?
- How to read integers from a file using BufferedReader in Java?
- How to read a text file from resources in Kotlin?
- How to read a text file in Selenium with python?
- How to read an entire line from a text file using Python?
- How to read a number of characters from a text file using Python?
- How to read a text file in Python?
- How to read text file into a list or array with Python?
- Read in a file in C# with StreamReader
- Read integers from console in Java
- How to read a simple text file in Android App?
- Read/Write Class Objects from/to File in C++
- Write a C program to read a data from file and display
- How to read a file from assets on android?

Advertisements