Hey all,
I am trying to read in a line from a file. The line will normally contain a string followed a number.
Eg/ NumberOfElements 1500
I only require the number.

I have been trying to read in the line storing the string as "text" and the number as "numOfInts".
I have delimited my getline with ' ', however the compiler doesnt seem to understand getline!

Error 1 error C3861: 'getline': identifier not found
Is there anyother way to get the number without the text? Or getting the current code to work.

I am using :-
#include <iostream>
#include "string.h"
#include "assert.h"
using namespace std;

istream& operator>>(istream &in, ArrayIntStorage &A){
	int numOfInts;
	string text;
	getline(in, text, ' '); //Error
	in >> numOfInts;
	A._size = numOfInts;
	A._text = text;
	A.addArray(A);
	for(int i=0;i<numOfInts;++i){
		int value;
		in >> value;
		A._data[i] = value;
	}
	return in;
}

Many Thanks

>> #include "string.h"

You need to #include <string> instead of this. string.h is the same as the c++ cstring library, which is used for functions on c-style char-array strings, not std::strings.

Edited 6 Years Ago by Nick Evan: n/a

Since you are reading from a file you need #include <fstream> also I would use an ifstream object such as

ifstream& operator>>(ifstream &in, ArrayIntStorage &A)

Thanks Nick, the <string> did the job......
i wasnt aware that using string.h, would make a difference
Many Thanks

This article has been dead for over six months. Start a new discussion instead.