I have started a code to declare what I need...now I need to input the information from a file each line is a song with a space inbetween...
Then after I get the data I have to be able to seach by artist or title...and output matches

PLEASE help...
this is what i have so far...

#include <iostream>
#include <fstream>
using namespace std;

const int totalSongs=50;

int main ()
{
	struct SongInfo //Declares Struct
	{
		string ArtistName;
		string Title;
		string Style;
		int LengthinSeconds;
		string notes;
		float Price;
	};
	SongInfo Songs[totalSongs]; //Declares Array

	return 0;
}

I believe this is how I would input the data but i'm not totally sure on that either...

#include <iostream>
#include <fstream>
using namespace std;

const int totalSongs=50;

int main ()
{
	struct SongInfo //Declares Struct
	{
		string ArtistName;
		string Title;
		string Style;
		int LengthinSeconds;
		string Notes;
		float Price;
	};
	SongInfo Songs[totalSongs]; //Declares Array

	ifstream inData;
	inData.open("songinfo.in");

	int m;
	for(int m=0; m<totalSongs; m++)
		cin  >> Songs[m].ArtistName >> Songs[m].Title >> Songs[m].Style >> Songs[m].LengthinSeconds >> Songs[m].Notes >> Songs[m].Price;

	inData.close();
	return 0;
}

>>I believe this is how I would input the data but i'm not totally sure on that either...

Run the damn code and tell us if it worked fine or gave error. If error, what error?

Here is what i got...I have an error at the end...in the for loop... I will post error at end of code... The purpose of the code is to create a struct array and read information from file...(code below) eventually i will add the option to search..also side note no output file needed...just read data and search...

#include <iostream>
#include <fstream>
using namespace std;



int main ()
{
	const int TotalPaintings=30;
	struct PaintingInfo //Declares Struct
	{
		string ArtistName;
		string Title;
		string Medium;
		int Size;
		string Room;
		float Price;
	};
	PaintingInfo Paint[TotalPaintings]; //Declares Array

	fstream inData;
	inData.open("PaintingInfo.dat");
	if (!inData)
	{
		cout << "Can't open file in PaintingInfo.dat" << endl;
	};
	int count=0;
	for(count=0; count < TotalPaintings; count++ );
	{
		>> Paint[count].ArtistName(); >> Paint[count].Title(); >> Paint[count].Medium(); >> Paint[count].Size(); >>	Paint[count].Room(); >>	Paint[count].Price();
	}
	return 0;
}

----------------------------
main.cpp(30) : error C2064: term does not evaluate to a function taking 0 arguments
main.cpp(30) : error C2143: syntax error : missing ';' before '>>'
main.cpp(30) : error C2143: syntax error : missing ';' before '>>'
main.cpp(30) : error C2143: syntax error : missing ';' before '>>'
main.cpp(30) : error C2143: syntax error : missing ';' before '>>'
main.cpp(30) : error C2143: syntax error : missing ';' before '>>'
1>Prog1 - 6 error(s), 0 warning(s)

Well, take a look at line 30, which is the expression where you read in all of your data.

Remember, an ifstream object will be used in the exact same way as we would use a cin object, but we are reading in from a file instead of the console.

Also, notice how you seem to be trying to call functions all throughout this line. You shouldn't be trying to do this. You should be treating them like normal variables, besides the Paint[count]. prefix.

Hopefully this helps you out.

Peace,
Bodom

do you think it would work if we... replaced the code in line 30 with

inData >> Songs[m].ArtistName;
inData >> Songs[m].Title;
inData >> Songs[m].Style;
inData >> Songs[m].LengthinSeconds;
inData >> Songs[m].Notes;
inData >> Songs[m].Price;

Im just not sure how to even input it into the struct array correctly

That should work. Though if you just replaced cin with indata on line 25 in post #3 that style should work, too. It's time to put one (or both) style(s) to work by adding some output code to confirm it does what you want and giving it a test drive.

ok i made the change but I have a new error code... any thoughts here is the revised code now... errors at end

#include <iostream>
#include <fstream>
using namespace std;



int main ()
{
	const int TotalPaintings=30;
	struct PaintingInfo //Declares Struct
	{
		string ArtistName;
		string Title;
		string Medium;
		int Size;
		string Room;
		float Price;
	};
	PaintingInfo Paint[TotalPaintings]; //Declares Array

	fstream inData;
	inData.open("PaintingInfo.dat");
	if (!inData)
	{
		cout << "Can't open file in PaintingInfo.dat" << endl;
	};
	int count=0;
	for(count=0; count < TotalPaintings; count++ );
	{
		inData >> Paint[count].ArtistName();
		inData >> Paint[count].Title();
		inData >> Paint[count].Medium();
		inData >> Paint[count].Size(); 
		inData >> Paint[count].Room();
		inData >> Paint[count].Price();
	}
	return 0;
}

--------------------
ERRORS
main.cpp(30) : error C2064: term does not evaluate to a function taking 0 arguments
main.cpp(31) : error C2064: term does not evaluate to a function taking 0 arguments
main.cpp(32) : error C2064: term does not evaluate to a function taking 0 arguments
main.cpp(33) : error C2064: term does not evaluate to a function taking 0 arguments
main.cpp(34) : error C2064: term does not evaluate to a function taking 0 arguments
main.cpp(35) : error C2064: term does not evaluate to a function taking 0 arguments

ANY THOUGHTS???

>>inData >> Paint[count].ArtistName();

You are treating ArtistName as though it were a function. Remove the () and that line will compile ok. Same with the other lines (31-35).

A whole new code an problem...

// #include <iostream>
#include <fstream>
using namespace std;
const int TotalPaintings=30;

void search (string[],string[],string[],int[],string[],float[]);
int main ()
{
	string ArtistName[TotalPaintings];
	string Title[TotalPaintings];
	string Medium[TotalPaintings];
	int SizeL[TotalPaintings];
	int SizeW[TotalPaintings];
	string Room[TotalPaintings];
	float Price[TotalPaintings];

	fstream inData;
	inData.open("PaintingInfo.dat");
	if (!inData)
	{
		cout << "Can't open file in PaintingInfo.dat" << endl;
	};
	int c=0;
	for(c=0; c<TotalPaintings; c++)
	{
		inData >> ArtistName[c] >> Title[c] >> Medium[c] >> SizeL[c] >> SizeW[c] >> Room[c] >> Price[c];
	}
	return 0;
}

Here are the error messages I got... its error
main.cpp(26) : error C2679: binary '>>' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)I have no idea what that means or how to fix it... its the InData >>line...

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