Cannot write vector to file / ostream

Hi,
I’m writing a macro that reads out a data file which provides in some lines certain values. These are stored in a vector. That does work but when I try to write this vector to a new file I receive the following error:

[quote]Error: link requested for unknown class ostream_iterator /…/analysis/APDs/AutoDict_ostream_iterator_string_.cxx:6:
Error: unknown class ostream_iterator in “#pragma link C++ class ostream_iterator::*”! Egnoring it.
Warning: Error occurred during reading source files
Warning: Error occurred during dictionary source generation
!!!Removing /home/…/analysis/APDs/AutoDict_ostream_iterator_string__cxx_ACLiC_dict.cxx /…/analysis/APDs/AutoDict_ostream_iterator_string__cxx_ACLiC_dict.h !!!
Error: /usr/bin/rootcint: error loading headers…
Error in : Dictionary generation failed![/quote]

Actually I’m only focused on handling the reading and writing so that’s why nothing else happens in the code. That’s the code:

[code]#include
#include
#include
#include
#include
#include
#include

using namespace std;

void compare(char *inputfile=“Test.txt”, char *outputfile=“Output.txt”)
{
vector vector_lines;
string line;
ifstream apd_file;
apd_file.open(inputfile);
if(!apd_file) cerr << “File “” << inputfile << “” not found\n” << endl;
else
{
ofstream Output(outputfile);
while(getline(apd_file,line))
{
if(line.length() > 1 && line[0] == ‘f’ && line[1] == ‘i’ && line[2] == ‘t’)
{
getline(apd_file,line);
getline(apd_file,line);
vector_lines.push_back(line);
cout << line << endl;
}
}
if(vector_lines.size()==0)
{
cout << “No parameters found” << endl;
}
copy(vector_lines.begin(), vector_lines.end(), ostream_iterator(Output));
Output.close();
apd_file.close();
}
}[/code]

Can someone help ? Thank you in advance!

Hi,

apart from the fact that line

void compare(char *inputfile="Test.txt", char *outputfile="Output.txt")

should read

void compare(const char *inputfile="Test.txt", const char *outputfile="Output.txt")

I am compiling the macro just fine with ROOT6 on osx. What version of ROOT are you using? Which compiler? On which OS?

Danilo

[quote=“dpiparo”]Hi,

apart from the fact that line

void compare(char *inputfile="Test.txt", char *outputfile="Output.txt")

should read

void compare(const char *inputfile="Test.txt", const char *outputfile="Output.txt")

Danilo[/quote]
Hi, sure, thanks!

[quote=“dpiparo”]
I am compiling the macro just fine with ROOT6 on osx. What version of ROOT are you using? Which compiler? On which OS?Danilo[/quote]
It’s on ubuntu and the software center displays root-system-bin 5.34.14-1build1.
I guess I shall update ? Didn’t know there’s a new version. Despite I thought ubuntu updates all the stuff automatically.

Hi,

5.34.14 is a release of 3 years ago. Perhaps you could try a recent one from this list? root.cern.ch/releases

Cheers,
Danilo

I installed it but I’ve to execute thisroot.sh every time. How do I set it as the regular version ?

Hi,

I think the general rules for Linux/OSx are the one to follow here.
You can modify the bashrc (or equivalent) to properly setup the environment of your shells.

Cheers,
Danilo

Hi,

thanks so far. How exactly do I do this ? In the .bashrc is no root, I thought I just could change the directory or something like this.
Do I have to enter an alias which executes thisroot.sh in the given directory ?

Greetings, Ben

Hi Ben,

perhaps you can have a look to this post* or something equivalent.

Cheers,
Danilo

unix.stackexchange.com/questions … -variables

You can just add to your .bashrc at the end:

[quote=“dpiparo”]Hi Ben,

perhaps you can have a look to this post* or something equivalent.

Cheers,
Danilo

unix.stackexchange.com/questions … -variables[/quote]

Ok, thanks! How do I know the variables I have to set ? Are they the same as in the link above ?

[quote=“ferhue”]You can just add to your .bashrc at the end:

Thanks, will try that out!

I’m not sure what I exactly have to do:

The extracted folder is /home/ben/root-6.06.08/ and the folder I installed root is /home/ben/root

so source /pathToYourRoot/bin/thisroot.sh

is then

/home/ben/root-6.06.08/ /home/ben/root/bin/thisroot.sh ?

When I open shell I receive “bash: /home/ben/root-6.06.08/: Is a directory”. What do I have to change ? Thank you in advance!

Open your file .bashrc with a text editor and write this line:

source /home/ben/root/bin/thisroot.sh

You have to write really “source”, do not replace it with the location of the source code.

The next time you open a terminal, you can call root directly.

ah, it’s a command :laughing:

Magic happened, it works! Thank you all!