I am writing a program that reads in a file and converts the data to a different format. I am having issues with using the end of file function. The program compiles with out any error but when I run it I think it gets stuck in an infinite loop. Can anyone tell me what I am doing wrong? I am just learning C++ so any and all advice is appreciated!
Code:
/*
* RasMolMaker
*
*
* Created by on 6/22/10.
* Copyright 2010 __MyCompanyName__. All rights reserved.
*
*/
#include <fstream>
#include <iostream>
#include <string>
int main(const int argc, const char** argv)
{
char ch;
const char* c_str();
std::string str,suffix,RasFile;
std::string filename;
suffix = ".pdb";
// Get filename and open stream
std::cout << "Enter filename:\n";
std::cin >> filename;
std::cout << "Opening " << filename << "...\n";
std::ifstream infile(filename.c_str());
// Create RasMol file and open stream
RasFile = filename + suffix;
std::cout << "Output will be to file " << RasFile << "\n";
std::ofstream outfile(RasFile.c_str());
int index = 1;
double x,y,z;
while (!infile.eof())
{
//infile.get(ch, 1);
if (ch == 'm')
{
//infile.getline(str, '\n');
continue;
}
else {
infile >> x >> y >> z;
outfile << "ATOM " << index;
index ++;
}
}
return 0;
}
Edit: Also, when I uncomment the infile.get and infile.getline I get a ton of error messages. The first one is:
Code:
RasMolMaker.cpp:35: error: no matching function for call to ‘std::basic_ifstream<char, std::char_traits<char> >::get(char&, int)’
/usr/include/c++/4.2.1/istream:292: note: candidates are: typename std::basic_istream<_CharT, _Traits>::int_type std::basic_istream<_CharT, _Traits>::get()
[with _CharT = char, _Traits = std::char_traits<char>]