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

Recommended Answers

All 3 Replies

>> #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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.