473,396 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help Needed, Please!!!! Read File And Put Into Arrays

I need some help reading in a file that has a column with the student's name and then a column with their score.
I need to input this into 2 seperate arrays. One for the names and one for the scores.
I have to use a String Array and a Int Array. I can't figure out how to get it into a String array. I keep getting errors.

Any help would be greatly appreciated!!!


This is what I have so far:
#include <iostream>
#include <fstream>
#include <cstring>
#include <iomanip>
#include <cmath>
using namespace std;

ofstream fout;
ifstream fin;

class StudentStat
{
private:
int Size;
string Names[20];
int Scores[20];
float Avg,
StDev,
Median;
int High_Score,
Low_Score,
Range;
void Storem();

public:
void Input();
void Calc_Avg();
void Calc_StDev();
void Calc_Median();
void range();
void Calc_HighLowRange();
void Output();
};
void StudentStat::Input()
{

for(int i=0;i<20;i++)
{

fin>>Names[i];
fin>>Scores[i];
cout>>Names[i];
cout<<Scores[i];
}

}
int main()
{
StudentStat Studobj;
fin.open("EvenClass.txt");
while(!fin.eof())
{
Studobj.Input();
}
fin.close();
return 0;

}
Oct 29 '06 #1
3 2623
Ganon11
3,652 Expert 2GB
I need some help reading in a file that has a column with the student's name and then a column with their score.
I need to input this into 2 seperate arrays. One for the names and one for the scores.
I have to use a String Array and a Int Array. I can't figure out how to get it into a String array. I keep getting errors.

Any help would be greatly appreciated!!!


This is what I have so far:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <fstream>
  3. #include <cstring>
  4. #include <iomanip>
  5. #include <cmath>
  6. using namespace std;
  7.  
  8. ofstream fout;
  9. ifstream fin;
  10.  
  11. class StudentStat
  12. {
  13. private:
  14.     int Size;
  15.     string Names[20];
  16.     int Scores[20];
  17.     float Avg,
  18.         StDev,
  19.         Median;
  20.     int High_Score,
  21.         Low_Score,
  22.         Range;
  23.     void Storem();
  24.  
  25. public:
  26.     void Input();
  27.     void Calc_Avg();
  28.     void Calc_StDev();
  29.     void Calc_Median();
  30.     void range();
  31.     void Calc_HighLowRange();
  32.     void Output();
  33. };
  34. void StudentStat::Input()
  35. {
  36.  
  37. for(int i=0;i<20;i++)
  38. {
  39.  
  40. fin>>Names[i];
  41. fin>>Scores[i];
  42. cout>>Names[i];              // <---- Here's your problem.  Replace the >> with <<
  43. cout<<Scores[i];              // a.k.a. "cout << Names[i] << " ";
  44. }
  45.  
  46. }
  47. int main()
  48. {
  49. StudentStat Studobj;
  50. fin.open("EvenClass.txt");
  51. while(!fin.eof())
  52. {
  53. Studobj.Input();
  54. }
  55. fin.close();
  56. return 0;
  57.  
  58. }
Found your error - for one of your cout statements, you say cout >> Names[i]; - this should use << instead. Try that.
Oct 29 '06 #2
It gives me the error binary '<<' :no operator found which takes right hand operand to type 'std::string'(or there is no acceptable conversion)
It says the same thing for '>>'.

Not sure where to go from here.. I have tried to look up sample code like this, but I can't seem to find anything. Without using a vector.

Thanks for your help!
Oct 29 '06 #3
Ganon11
3,652 Expert 2GB
Now that's very strange...there is a << operator on cout, and strings are able to be outputted in this way...This isn't likely, but have you tried adding #include <string> to your code? I usually use that header file instead of cstrings.
Oct 29 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: John | last post by:
Hi all Can anyone point me in the direction of a script which would get a list of files from a specified folder and then store them in an array. I guess i could write my own, but i don't have...
15
by: Buck Rogers | last post by:
Hi guys! Task 1: Write a program which presents a menu with 5 options. The 5th option quits the program. Each option should execute a system command using system(). Below is my humble...
2
by: | last post by:
internal struct ConstantValue { internal DateTime EffectiveFrom; internal DateTime EffectiveThrough; internal DateTime DateValue; internal double DoubleValue; } internal struct Constant {
5
by: Buchwald | last post by:
hello group, I have a long (large) script that shows a random picture when a webpage is refreshed. It's long because i have a lot of pictures: 246 Here is some code:...
9
by: silverchrono | last post by:
this is my first semester in C and im trying to figure out how to reset a counter. heres why im trying to do. void text() 59 printf("You can end entering the text by using '#'\n"); 60 int...
4
by: inspiretechnologies | last post by:
Hi all, I'm creating a Php page with connection to a MySql database. In this page, I get all the articles (text) of a member, and when the article's length exceeds 500 characters, a link "read...
0
by: AMP | last post by:
Hello, (I sent this to the general NG too. I meant to send it here) I am having a tough time reading from a serial port. My code allows me to ask the device for 255 bytes at 9600 baud.I have to do...
4
by: Dave G | last post by:
I've just been informed that an Access 2003 based system in use at one of my customers now needs to send data in the form of an XML file to a webservice. They told me it was simple - but I don't...
3
by: Rory Becker | last post by:
The following code is being used in a VB6 program to read and write a simple binary file. I need to move things into the 21st century and recode this in VB.Net The new VB.Net program will need...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.