cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
having a vector read multiple data file
having a vector read multiple data file
Oct 7, 2014 at 3:18am UTC
rockarunnie
(1)
Im suppose to create a program to read a data file using vectors now what i started so far it only reads in the first number and thats all any idea on what i went wrong?
the newdata file contains 10 20 30 40 50
#include "stdafx.h"
#include<iostream>
#include<fstream>
#include<iomanip>
#include<vector>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
vector<int> Salery;
int x;
char choice;
ifstream dataFile;
dataFile.open("newdata.txt");
while (dataFile >> x)
Salery.push_back(x);
if (Salery.size () ==0)
cout << "no elements \n";
else
{
for (int i = 0; i<Salery.size(); i++)
{ cout <<Salery.at(i);
cout << "\n";
}}
Topic archived. No new replies allowed.