0

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?

pseyfert
  • 3,263
  • 3
  • 21
  • 47
Woj
  • 449
  • 1
  • 5
  • 15
  • Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ken White Aug 30 '20 at 01:49
  • @user4581301 Do you think I should omit some of the `#includes` if they are unnecessary here? – Woj Aug 30 '20 at 02:45
  • My view on includes is to always include the headers for everything you use, nothing less and nothing more. – user4581301 Aug 30 '20 at 06:15
  • How are you trying to run the code? Interpreted (from the commandline with `root yourfile.C` or from the root prompt `.L yourfile.C` / `.x yourfile.C`? or compiled through root `root yourfile.C+` / `.L yourfile.C+` / `.x yourfile.C+`? or compiled like a "normal" c++ application `g++ yourfile.C $(root-config --cflags) $(root-config --libs)`?) – pseyfert Aug 30 '20 at 21:41
  • @user4581301 there is the root-framework tag. it's even linked from the description of the root tag due to the ambiguity. and it describes where to find the root support forum (during working hours there is staff paid to answer questions) – pseyfert Aug 30 '20 at 21:43
  • So I see. When you type root into the tags, it doesn't show up. Neither does anything useful for CERN. Next time I'll go digging through the grand list of all tags. – user4581301 Aug 31 '20 at 03:21

0 Answers0