Hi i have been tryin to read a gmsh text file which indicates integers, floats and some strings. the code has been posted below. i have also tried compiling and running some codes from tutorials and other sites but they share the same problem with my code. and the problem is that the .txt file opens fine but i keep getting reading error no matter what i do.
this results in myfile.fail() to return a true value for the first iteration. i added the seekg() just to make sure i will read from the beginning but the code doesnt work without it. any how the text file that i want to read is simply
and i have no idea what could be wrong with my code
any help would be greatly appreciated
HTML:
#include <iostream>
#include <fstream>
#include <math.h>
#include <string>
#include "auxiliary_functions.h"
#include "math_functions.h"
#include "data_structure.h"
using namespace std;
int main () {
const int max_num_char_in_line = 512;
std::cout << "This commandline tool has been designed to solve the 2D pure advection problem presented as the term project to the Finite Element Method course by Dr. Manzari. The code has been written by Bamdad Hosseini 85110129. The code has been written using apples Xcode 3.1 and compiled under gcc 4.2 and LLVM gcc 4.2 compilers. The problem is solved on a unit square using linear triangular elements generated by Gmsh 2.4.2. \n please push the enter if you wish to run this program." << endl;
//std::cin.get();
std::cout << endl;
//std::cout << "please enter the address of the Gmsh mesh file:" << endl;
string mesh_file_address;
//std::cin >> mesh_file_address;
//std::cin.get();
mesh_file_address = "/Users/bamdadhosseini/Desktop/mesh/FEMmesh.txt";
int number_of_nd_ele[2];
node *global_nodes;
element *global_elements;
int nd_ele_line[2];
float x;
ifstream myfile;
myfile.open("/Users/bamdadhosseini/Desktop/test.txt");
if (myfile.is_open())
std::cout << "file is open" << endl;
myfile.clear();
myfile.seekg(0);
while (!myfile.eof()) {
myfile >> x;
if (myfile.fail()) {
std::cout<< "read error" << endl;
exit(1);
}
std::cout << x << endl;
}
myfile.close();
}
this results in myfile.fail() to return a true value for the first iteration. i added the seekg() just to make sure i will read from the beginning but the code doesnt work without it. any how the text file that i want to read is simply
HTML:
1 2 32 445 6 7
123 435 65 7
and i have no idea what could be wrong with my code