I want to read a text file using following function, This functions are in class Mesh which takes std::string mesh_name in the constructor. Also the mesh name_ is class variable.
a likely cause: do not use eof()
say
while(s>>buf)
{
}
your logic is probably wrong too. try strcmp, not strstr. strstr (substring) will find a match if you looked for "THE" and found OTHER
strcmp is exact match comparison.
Well, for one thing it should be "start" instead of "Start" since you are lowercasing the string you compare to.
If that's not it then you need to at least show us TakeOutSpaces and give a small example of the input.
jonnin has a good idea.
Also remember that "start" in the FindWord call needs to be all lowercase since FindWord first converts the input word to lowercase.
Unless I'm missing something re the input file, this seems vastly overcomplicated for reading a file of the provided structure. Using:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <fstream>
#include <iostream>
#include <string>
int main() {
std::ifstream ifs("mesh.txt");
if (!ifs)
return (std::cout << "Cannot open file\n"), 1;
for (std::string line; std::getline(ifs, line) && line != "Start";);
for (double x, y, z; ifs >> x >> x >> y >> z; ) {
// Process x y z here
std::cout << x << " " << y << " " << z << '\n';
}
}