I am new C++ and am using the CERN ROOT interpreter 6.22/00 in Ubuntu 18.04 (required for course). I am trying to write a code that simple reads columns of data from a file and write the data to an output file. Here is a minimally reproducible version of my code where I am reading from arrays instead of from a file:
# include <iostream>
# include <fstream>
//# include <math.h>
# include <iomanip>
//# include <cmath>
//# include <stdlib.h>
# include <cstdlib>
//# include <fstream.h>
//# include <string.h>
# include <string>
//# include <direct.h>
//# include <dos.h> //For Sleep()
using namespace std;
int main()
{
char outputFileName[30] = "output.dat";
int NumOfRows = 5;
int nCount[5] = {0, 1, 2, 3, 4};
int nCount2[5] = {1, 2, 3, 4, 5};
cout<<"Creating output file"<<endl;
ofstream outFile(outputFileName);
outFile<<"1st Param"<<setw(15)<<"2nd Param"<<endl; //Header
for (int a = 1; a < NumOfRows; a++){
// Reading rest of file
outFile << nCount[a] << nCount2[a];
}
outFile<<""<<endl;
// Warning if file cant be opened
if(!outFile.is_open()){
cout << "Error opening file. \n";
//cout << "Giving Retry... \n";
}
if(outFile.is_open()){
cout<<"Output File was opened successfully"<<endl;
}
if(outFile.good()){
cout<<"Output File is ready for reading"<<endl;
}
outFile.close();
if(!outFile.is_open()){
cout<<"Output File closed successfully"<<endl;
}
return 0;
}
However, when I run this code, I get the error:
IncrementalExecutor::executeFunction: symbol '_ZStorSt13_Ios_OpenmodeS_' unresolved while linking [cling interface function]!
You are probably missing the definition of std::operator|(std::_Ios_Openmode, std::_Ios_Openmode)
Maybe you need to load the corresponding shared library?
IncrementalExecutor::executeFunction: symbol '_ZSt4setwi' unresolved while linking [cling interface function]!
You are probably missing the definition of std::setw(int)
Maybe you need to load the corresponding shared library?
I tried the error suggestion and looked up the library for std::setw(int)
, but I saw that it is defined in <iomanip>
, which I have already included in the code. What am I missing here?