I was looking through the data structure tutorial and I thought I will do my own example for structures, but it gives the following errors. Even the sample program that is given in the website is giving the same list of errors...I have attached the code and the errors for your easy reference...thanks for the help...
//structures programming
#include<iostream>
#include<sstream>//this is to read strings from the command line and use them as input.
#include<string>//this is to do all sorts of matter with strings.
using namespace std; //struct declaration and all comes after this only.
struct branch{//branch is the name of the structure, from now on it will be treated like a datatype like int or float
string type;
int hits,misses;//hits and misses are members of the structure and they are of datatype branch
}mine,yours;//these are the objects of datatype product.
void printing(branch method)//the d.type can be used in functions too.
{
cout<<"hits:"<<method.hits;
cout<<"misses:"<<method.misses;
}
int main()
{
string mystr;//sh: u will have to do this because this is whre the string that is read from the CLI is temporarily stored.
branch gshare;//i have done this jus to show tht a var of type branch can also be declared like this
cout<<"enter the type of branch prediction"<<endl;
//getline(cin,mystr);//sh: u made a mistake here. It is just getline...no cin b4 and all...
//stringstream(mystr) >> yours.type;//NOTE THIS COMMAND, U GOT IT WRONG
cout<<"shiva, enter your type of branch predictor"<<endl;
getline(cin,mine.type);//showing another method of reading from the command line.
if((mine.type=="gag") || (yours.type=="gag"))
{
mine.hits=100;
yours.hits=100;
mine.misses=100;
yours.misses=100;
}
/*if(mine.type=="gap" || yours.type=="gap")
{
mine.hits=yours.hits=110;
mine.misses=yours.misses=90;
}
if(mine.type=="pag" || yours.type=="pag")
{
mine.hits=yours.hits=120;
mine.misses=yours.misses=80;
}
if(mine.type=="pap" || yours.type=="pap")
{
mine.hits=yours.hits=130;
mine.misses=yours.misses=70;
}*/
printing(yours);
printing(mine);
return 0;
}
you could always do what it suggests and try using istream. Personally I can't see what is wrong with it, but it is extremely hard to read without code tags, you should use these in future, the button that looks like <>