include include include using namespace std int main Declar

#include
#include
#include

using namespace std;

int main()
{
//Declaring constant
int const size =2;

//Creating string type array
string names[size];

//Creating int type array
int age[size];

//defines an input stream for the data file  
ifstream inputFile;

//Opening the input file
inputFile.open(\"D:\\\\text.txt\");

//Getting the data from the file and populate those value into arrays
for (int i = 0; i {
   //Getting the data from the file
inputFile >> names[i]>>age[i];
}


//This for loop will display the data in the arrays
for (int i = 0; i {
//displaying the data in the arrays
cout << names[i]<<\" \"< }

//Closing the input stream
inputFile.close();

return 0;
}

________

does not work - giving me two long numbers like it is convering the input

have tried several files with a string and a number

just gives two longs numbers ??????????????????? c++

update??????

read from an input text file /name and grade/ into parallel arrays - output simple right? but I am geetting two long numbers - no name no number

Solution

Answer

The reuirement can be achieved by the below code::

#include <iostream.h>
#include <string.h>
#include <fstream.h>

int main()
{
   ifstream file(\"D:\\\\text.txt\");
   int i;
   string names[100];
   string age[100]; //numbers are also taken as string
   //after reading from the file this can be converted into integer and
   //stored in integer array
   if(file.is_open())
   {


       for(i = 0; i < 100; ++i)
       {
               file >> names[i]>>age[i];
       }
   }
   for(i = 0; i < 100; ++i)
       {
               cout<<names[i]<<\" \"<<age[i];
       }

}

#include #include #include using namespace std; int main() { //Declaring constant int const size =2; //Creating string type array string names[size]; //Creating
#include #include #include using namespace std; int main() { //Declaring constant int const size =2; //Creating string type array string names[size]; //Creating

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site