[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 290
  • Last Modified:

substring, date

Hi experts,
I have 2 columns: row_elem[1], and row_elem[10]
for example.
row_elem[1] ,                                 row_elem[10]
aaaaa NFLFAN sssss,                          01022004      date format mmddyyyy
aaaaa NFLFAN sssss,                          01152004
...                                                     ...
I check row_elem[1] first, if substring has NFLFAN, and if dd=15, then print 01162004 ( adding 1 to day, that is 16, always 16 )
otherwise print 01022004

My code is like this, but its not working. please help
...
main(int arc, char *arv[])
{
    ifstream fin("test.csv");
    ofstream fout("fout.txt");
    string row_read;
    while( getline(fin, row_read) )
    {

        vector<string> row_elem;
        GetFields(row_read, row_elem, ',');
....
string mm;
string dd;
string yyyy;

mm = row_elem[10].substr(0,2);
dd = row_elem[10].substr(2,2);
yyyy = row_elem[10].substr(4,4);
//cout << mm.c_str() << endl;

char pch[50];
char *ss1;
ss1 = strstr(row_elem[1],"NFLFAN");
if ( ss1 )
{
     cout << mm16yyyy <<endl;
}
else
     cout << mmddyyyy << endl;
}   // end of while
}

0
justinY
Asked:
justinY
  • 3
  • 3
  • 2
  • +1
1 Solution
 
IndrawatiCommented:
I don't really understand your question, but I found a mistake in your code:

if ( ss1 )
{
     cout << mm16yyyy <<endl;
}
else
     cout << mmddyyyy << endl;

Should be

if ( ss1 )
{
     cout << mm << 16 << yyyy <<endl;
}
else
     cout << mmddyyyy << endl;
0
 
HendrikTYRCommented:
Have you tried:

if ( ss1 )
{
     cout << mm << "16" << yyyy << endl;
}
else
     cout << mm << dd << yyyy << endl;
}
0
 
HendrikTYRCommented:
Sorry, posted same time
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
itsmeandnobodyelseCommented:
That is wrong as well:

>>>> ss1 = strstr(row_elem[1],"NFLFAN");

change to

      if ( row_elem[1].find("NFLFAN") != string::npos)
     {
        cout << mm << "16" << yyyy << endl;
     }
     else
         cout << mm << dd << yyyy << endl;
    }

Regards, Alex

0
 
HendrikTYRCommented:
... or:

char *ss1;
ss1 = strstr(row_elem[1].c_str(), "NFLFAN");
if ( ss1 )
{
     cout << mm << 16 << yyyy <<endl;
}
else
     cout << mm << dd << yyyy << endl;
0
 
justinYAuthor Commented:
Thanks guys,
I forgot this if dd = 15, then cout <<mm<<16<<yyyy;
so my code is

stringstream oss1;
stringstream oss2;

if ( ( row_elem[1].find("NFLFAN") != string::npos) && (aoti(dd) = 15))
     {
        oss1 << setw(8) << mm << "16" << yyyy;
     }
     else
         oss2 << setw(8) << mm << dd << yyyy;
    }

      fout << setw(8) << oss1.str().c_str() << endl;
but I have compiling error, whats wrong ?
0
 
itsmeandnobodyelseCommented:
>> && (aoti(dd) = 15)

suppose you want

     && (dd == 15)

instead.

Regards, Alex
0
 
itsmeandnobodyelseCommented:
Correction: dd is a string, so you need

&& (dd == "15")


Regards, Alex

0
 
justinYAuthor Commented:
Hi Alex,

I fixed it by doing this
 && (aoti(dd.c_str()) == 15)

Thanks
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now