text file into two arrays

i am trying to take text already in a file and store them into two different arrays. One array will be the name and the other a test score.
i am not sure if my logic is even correct but i have problems getting the info into two different arrays. The text file has a space between the name and the score, my understanding is that the space would be null breaking point at which the taking in of info will stop.

I tried quite a few things with no success but i have a new idea but ran into an error using strlen which said that it cannot convert a char to a conts.

i would like to know if my logic/approach is correct and why i have this problem with strlen.





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <cstring>
#include <string>


using namespace std;


int main(){
char name[50];
int score[50];

ifstream file_1("F:\\Data.txt");
for(int i = 0; i < 6; i++){
	file_1>> name[i];
		if(strlen(name[i])==0) // error here
			break;

		file_1 >> score[i];
		

}

for(int i = 0; i < 6;i ++)
	cout << name[i] << " " << score[i] << endl;



}



Thank you for your time
The problem stems from how you are trying to store the names.

I suggest you actually use the string class, i.e.
 
std::string name[50];


Then, instead of strlen, you can use the size() function of string.
thank you for your response but i have tried that and i still have the same error unless there is something else i am suppose to change along with that

sorry actually it does work with sizeof thank you


Last edited on
Could you post an example of the text you are trying to use with this program? Because this is my first time on this forum, I'll try my best to help you out, bro :)
Topic archived. No new replies allowed.