[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

substring, date

Posted on 2004-10-27
9
Medium Priority
?
288 Views
Last Modified: 2010-04-02
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
Comment
Question by:justinY
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 3

Expert Comment

by:Indrawati
ID: 12430536
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
 
LVL 3

Expert Comment

by:HendrikTYR
ID: 12430550
Have you tried:

if ( ss1 )
{
     cout << mm << "16" << yyyy << endl;
}
else
     cout << mm << dd << yyyy << endl;
}
0
 
LVL 3

Expert Comment

by:HendrikTYR
ID: 12430553
Sorry, posted same time
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 500 total points
ID: 12430599
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
 
LVL 3

Expert Comment

by:HendrikTYR
ID: 12430665
... 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
 

Author Comment

by:justinY
ID: 12434224
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
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 12434382
>> && (aoti(dd) = 15)

suppose you want

     && (dd == 15)

instead.

Regards, Alex
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 12434400
Correction: dd is a string, so you need

&& (dd == "15")


Regards, Alex

0
 

Author Comment

by:justinY
ID: 12435564
Hi Alex,

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

Thanks
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question