Getline errors while taking info from file

I'm having a few odd errors with getline. I've looked at my previous projects and I can't see what I'm doing wrong in comparison. I am using the same #includes as the other projects, and still getting the same issues. (not all includes are used, just grabbed them thinking I may use them, but don't want to jump and down on the page.)

1
2
3
4
5
6
7
8
9
10
#include <iostream>
#include <iomanip>
#include <string>
//#include <cctype>
//#include <ctime>
#include <sstream>
#include <fstream>
//#include <stdio.h>
//#include <time.h>
using namespace std;


1
2
3
4
5
6
7
8
9
	ifstream reg;
	reg.open("Registry.txt", ios::app);

	//if (!reg.is_open()) { cout << "File Currupted or Lost!" << endl; }
	//else {
		for (int x=0; !reg.eof(); x++){
				getline(reg, regArray[x][1]);	//Owner; Person's name or Business
				getline(reg, regArray[x][2]);	//Location bought from
				reg >> regArray[x][3];			//Serial 


Building gets these errors a few times.
error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_istream<_Elem,_Traits> &' from 'std::fstream'
Last edited on
After some playing around, apparently I have a hidden problem. The compiler thinks I'm trying to input with getline information to a 'char' variable, which I'm not. I think I have something messed up with my dynamic string array.
Here is my full piece of code with the change of how I figured this out.

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47



	int menu;
	string Temp;
	string owner;
	string location;
	string date;
	int charger;
	string serial;
	int completed;
	int y;
	int size = 5;
	string* regArray = new string[size];
	string NewRegArray[10][5];			//10 as a safegaurd to save often. 5 is Owner, Date, Location Bought, Charger Name, Serial Number.

	system ("cls");
	cout << "Loading Registry Data Base...";

	string tempIn;
	ifstream reg;
	reg.open("Registry.txt", ios::app);
	//if (!reg.is_open()) { cout << "File Currupted or Lost!" << endl; }
	//else {
		for (int x=0; !reg.eof(); x++){
				getline(reg, tempIn);	//Owner; Person's name or Business
				regArray[0][0] = tempIn;
				getline(reg, tempIn);	//Location bought from
				regArray[x][1] = tempIn;
				reg >> regArray[x][2];			//Serial
				reg >> regArray[x][3];			//Charger
				reg >> regArray[x][4];			//Date
				reg >> Temp;					//File input fix
				string* regArray2 = new string[size];
				for (int i = 0; i < size; ++i){
					regArray2[i] = regArray[i];}
				delete[] regArray;
				++size;
				regArray = new string[size];
				for (int i = 0; i < size - 1; ++i){
					regArray[i] = regArray2[i];}
				delete[] regArray2;
				y++;
	//	}
	}
	reg.close();
	cout << " DONE!" << endl;


Errors I get is:

1>c:\users\striker\documents\visual studio 2005\projects\serial sorter\serial sorter\addreg.cpp(27) : error C2440: '=' : cannot convert from 'std::string' to 'char'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\users\striker\documents\visual studio 2005\projects\serial sorter\serial sorter\addreg.cpp(29) : error C2440: '=' : cannot convert from 'std::string' to 'char'
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

I've been looking around on the internet and where I see examples for dynamic arrays is used with 'int' and 'char', why can't I do this with strings?
Last edited on
I finally got an answer from a classmate when we had time to talk.

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
	int menu;
	string Temp;
	string owner;
	string location;
	string date;
	int charger;
	string serial;
	int y = 0;
	int size = 1;
	string NewRegArray[10][5];			//10 as a safegaurd to save often. 5 is Owner, Date, Location Bought, Charger Name, Serial Number.

	struct regArray {
		string owner;
		string location;
		string serial;
		string charger;
		string date;
	};
	regArray* registration;
	registration = new regArray[size];

	system ("cls");
	cout << "Loading Registry Data Base...";

	string tempIn;
	ifstream reg;
	reg.open("Registry.txt", ios::app);
	if (!reg.is_open()) { cout << "File Currupted or Lost!" << endl; }
	else {
		for (int x=0; !reg.eof(); x++){
				getline(reg, tempIn);	//Owner; Person's name or Business
				registration[x].owner = tempIn;
				getline(reg, tempIn);	//Location bought from
				registration[x].location = tempIn;
				reg >> registration[x].serial;			//Serial
				reg >> registration[x].charger;			//Charger
				reg >> registration[x].date;			//Date
				reg >> Temp;					//File input fix

				regArray* reg2 = new regArray[size];
				for (int i = 0; i < size; ++i){
					reg2[i] = registration[i];}
				delete[] registration;
				++size;
				registration = new regArray[size];
				for (int i = 0; i < size - 1; ++i){
					registration[i] = reg2[i];}
				delete[] reg2;
				y++;
		}
	}
	reg.close();
	cout << " DONE!" << endl;
Topic archived. No new replies allowed.