Home > Back-end >  Teach a great god, the vector <string> array in the to find elements appeared a little problem
Teach a great god, the vector <string> array in the to find elements appeared a little problem

Time:09-23


HTML code is as follows, why output are all zero, should not be 1 1 1 0 0 1 0 0, exactly what is going wrong, about for a long time, please teach
 # include & lt; Iostream> 
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

using namespace std;
Using the namespace Eigen;


Int main ()
{

Ifstream file;
File. The open (" map_test2. TXT ");
String thisline;
Char * p;
string str;

Vector Autosome_id;


for(int i=1; i<23. I++)
{
Autosome_id. Push_back (to_string (I));
}
Vector : : iterator it;

While (getline (file, thisline, '\ n'))
{
P=strtok (& amp; Thisline [0], "\ t");

STR=p;

It=the find (autosome_id. The begin (), autosome_id. The end (), STR);

If (it!=autosome_id. End ())
{
Cout<1 & lt; }

The else
{
Cout<0}
}



}


Map_test2. TXT file below:

CodePudding user response:

Do not use the string as char []
2 strtok use wrong here also don't have to delete it directly
  • Related