Gighalen Posted November 23, 2010 Share Posted November 23, 2010 Let's say I have a single dimensional array containing 10 elements, and have 0123456789 on my standard input stream. How would I read these values into my array, with 1 digit per element? Quote Link to comment https://forums.phpfreaks.com/topic/219529-c-reading-single-integers-from-input-stream/ Share on other sites More sharing options...
Gighalen Posted November 23, 2010 Author Share Posted November 23, 2010 #include <iostream> #include <iomanip> #include <string> #include <fstream> using namespace std; int main(){ string inputFile; ifstream inFile; int count = 0; // keep track of number of integers read int numbers[19]; // array to store our integers cout << "Enter the name of the data file now: " << endl; cin >> inputFile; inFile.open(inputFile.c_str()); while(!inFile){ cout << "==> Error opening file: " << inputFile << endl; cout << "==> Try Again..." << endl; inFile.clear(); cout << fixed << "Enter the name of the data file now: "; cin >> inputFile; cout << inputFile << endl << endl << endl; inFile.open(inputFile.c_str()); } while(count <= 19 && inFile >> numbers[count]){ cout << numbers[count] << endl; count++; } system("pause"); return 0; } Quote Link to comment https://forums.phpfreaks.com/topic/219529-c-reading-single-integers-from-input-stream/#findComment-1138234 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.