Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

THE ERROR IN THE VECTOR STRING

[code]#include
#include
using namespace std;
int main(int arg, char*args[])
{
istream&getline(istream&is,string str,char delimiter);
vector*retrieve_text()
{
string file_name;
cout<<"please enter file name:";
cin>>file_name;
ifstream infile(file_name.c_str(), ios::in);
if(!infile)
{
cerr<<"sorry,can't open the file"<<file_name<<endl;
exit(-1);
}
else cout<<endl;
vector<string,allocator>*line_of_text=new vector;
string textline;
string texline;
typedef pairstats;
stats maxline;
int linenum=0;
while(getline(infile,textline,'
';))
{
cout<<"line read:"<<textline.size())
if(maxline.first<<textline.size())
{
maxline.first=textline.size();
maxline.second=lineum;
}
lines_of_text->push_back(textline);
lineum++;
}
return lines_of_text;
}
system("pause");
return 0;

}[/code]
There are a batch of errors in the compiler, the code is from the book "c++ prime third edition.

Comments

  • nandana121nandana121 Member Posts: 2
    : [code]: #include
    : #include
    : using namespace std;
    : int main(int arg, char*args[])
    : {
    : istream&getline(istream&is,string str,char delimiter);
    : vector*retrieve_text()
    : {
    : string file_name;
    : cout<<"please enter file name:";
    : cin>>file_name;
    : ifstream infile(file_name.c_str(), ios::in);
    : if(!infile)
    : {
    : cerr<<"sorry,can't open the file"<<file_name<<endl;
    : exit(-1);
    : }
    : else cout<<endl;
    : vector<string,allocator>*line_of_text=new vector;
    : string textline;
    : string texline;
    : typedef pairstats;
    : stats maxline;
    : int linenum=0;
    : while(getline(infile,textline,'
    ';))
    : {
    : cout<<"line read:"<<textline.size())
    : if(maxline.first<<textline.size())
    : {
    : maxline.first=textline.size();
    : maxline.second=lineum;
    : }
    : lines_of_text->push_back(textline);
    : lineum++;
    : }
    : return lines_of_text;
    : }
    : system("pause");
    : return 0;
    :
    : }[/code]:
    : There are a batch of errors in the compiler, the code is from the
    : book "c++ prime third edition.
    :
    hai,
    your question is not clear about what the error you are getting. As per me the declaration of vector variables may be worngly declared. because syntax for declaring vector is ::
    vector name(desired_size);

    ex:vector parkingGarage(10);


    so just check once and the link below will help you for your further rectificatio nof error
    http://www.codeproject.com/Articles/38600/String-and-vector-manipulation-through-example-Mor
  • nandana121nandana121 Member Posts: 2
    : [code]: #include
    : #include
    : using namespace std;
    : int main(int arg, char*args[])
    : {
    : istream&getline(istream&is,string str,char delimiter);
    : vector*retrieve_text()
    : {
    : string file_name;
    : cout<<"please enter file name:";
    : cin>>file_name;
    : ifstream infile(file_name.c_str(), ios::in);
    : if(!infile)
    : {
    : cerr<<"sorry,can't open the file"<<file_name<<endl;
    : exit(-1);
    : }
    : else cout<<endl;
    : vector<string,allocator>*line_of_text=new vector;
    : string textline;
    : string texline;
    : typedef pairstats;
    : stats maxline;
    : int linenum=0;
    : while(getline(infile,textline,'
    ';))
    : {
    : cout<<"line read:"<<textline.size())
    : if(maxline.first<<textline.size())
    : {
    : maxline.first=textline.size();
    : maxline.second=lineum;
    : }
    : lines_of_text->push_back(textline);
    : lineum++;
    : }
    : return lines_of_text;
    : }
    : system("pause");
    : return 0;
    :
    : }[/code]:
    : There are a batch of errors in the compiler, the code is from the
    : book "c++ prime third edition.
    :
    hai,
    your question is not clear about what the error you are getting. As per me the declaration of vector variables may be worngly declared. because syntax for declaring vector is ::
    vector name(desired_size);

    ex:vector parkingGarage(10);


    so just check once and the link below will help you for your further rectificatio nof error
    http://www.codeproject.com/Articles/38600/String-and-vector-manipulation-through-example-Mor
Sign In or Register to comment.