I am trying to use setprecision but I keep getting the error
Code:
RasMolMaker.cpp:124: error: ‘precision’ was not declared in this scope
I don't understand why I am getting this error when I include the <iomanip> header. Can someone tell me where I am going wrong? Thanks
BTW, the problem line is at the bottom of the main section at the end of the while loop.
My header file is:
Code:
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <ios>
#include <cstdlib>
void writeBash(char* file);
void writeCleanup();
void Clearspace();
void clearSpace();
and my code is:
Code:
#include "RasMolMaker.h"
int main(const int argc, const char** argv)
{
char ch,holder[100];
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;
//infile.open(filename.c_str());
*/
// Open config file for input
std::ifstream infile, infile2;
infile.open("config");
// Write formatting bash script
char* filename = "config";
writeBash(filename);
// Open scratch file for input
infile2.open(".17834039BOSUQWU239MBKA89");
/*
// Create RasMol file and open stream
RasFile = filename + suffix;
std::cout << "Output will be to file " << RasFile << "\n";
std::ofstream outfile;
//outfile.open(RasFile.c_str());
*/
// Open config.pdb for output
std::ofstream outfile;
outfile.open("config.pdb");
// Check files opened correctly
if (infile.fail())
{
std::cout << "Input file failed to open correctly\n";
}
if (outfile.fail())
{
std::cout << "Output file failed to open correctly\n";
}
if (infile2.fail())
{
std::cout << "Scratch file failed to open correctly\n";
}
// Find the size of the file
infile2.seekg(0, std::ios::end);
long len = infile2.tellg();
infile2.seekg(0, std::ios::beg);
double x,y,z;
int index = 0;
while(infile2.tellg() <= (len-2) && infile2.tellg() >=0)
{
if(index > 0 && index % 3 == 0)
{
outfile << "\n";
};
if (index % 3 == 0 )
{
if (index/3 < 10)
{
if (index/3 % 20 < 10) {
outfile << "ATOM " << index/3 << " N" << " ";
}
else {
outfile << "ATOM " << index/3 << " O" << " ";
}
}
if (index/3 >= 10 && index/3 < 100)
{
if (index/3 % 20 < 10) {
outfile << "ATOM " << index/3 << " N" << " ";
}
else {
outfile << "ATOM " << index/3 << " O" << " ";
}
}
if (index/3 >= 100 && index/3 < 1000)
{
if (index/3 % 20 < 10) {
outfile << "ATOM " << index/3 << " N" << " ";
}
else {
outfile << "ATOM " << index/3 << " O" << " ";
}
}
if (index/3 >= 1000 && index/3 < 10000)
{
if (index/3 % 20 < 10) {
outfile << "ATOM " << index/3 << " C" << " ";
}
else {
outfile << "ATOM " << index/3 << " C" << " ";
}
}
}
infile2 >> holder;
outfile << setprecision(4) << holder << " ";
index++;
}
// Check file position before closing
std::cout << "File length: " << len << "\n";
std::cout << "File position before closing: " << infile.tellg() << "\n";
infile.close();
outfile.close();
writeCleanup();
clearSpace();
return 0;
}
void writeBash(char* file)
{
// Open output file stream
std::ofstream out;
out.open("cleaner.sh");
// Write bash script
out << "grep -v 'molecule' " << file << "| grep -v 'BOUNDARY' | grep -v 'MOLECULES' | grep -v 'species' | grep -v 'nMolecule' | grep -v 'orthorhombi' | grep -v 'cubic' | grep -v 'tetragonal' > .17834039BOSUQWU239MBKA89";
// Make script executable
std::system("chmod +x cleaner.sh");
// Close filestream
out.close();
// Execute script
std::system("./cleaner.sh");
}
void writeCleanup()
{
// Open output filestream
std::ofstream out;
out.open("wipe.sh");
// Write bash script
out << "rm .17834039BOSUQWU239MBKA89";
// Make script executable
std::system("chmod +x wipe.sh");
// Close filestream
out.close();
// Execute script
std::system("./wipe.sh");
}
void clearSpace()
{
std::system("rm wipe.sh cleaner.sh");
}