how to integrate libxl functions in c++ - c++

Im trying to read excel sheets of xlsx file and convert each sheet to a csv file using libxl
i downloaded libxl 4.1.0 and followed this steps to integrate libxl in my code:
https://www.libxl.com/codeblocks.html
this is my code:
#include <iostream>
#include <fstream>
#include <string>
#include "libxl.h"
using namespace std;
using namespace libxl;
int main() {
Book* book = xlCreateBook();
if(book) {
if(book->load("0FUP3B0YZS_results.xls")) {
int sheetCount = book->sheetCount();
for(int i = 0; i < sheetCount; ++i) {
Sheet* sheet = book->getSheet(i);
if(sheet) {
string csvFileName = sheet->name() + ".csv";
ofstream csvFile(csvFileName.c_str());
if(csvFile.is_open()) {
int rowCount = sheet->lastRow();
for(int row = 0; row <= rowCount; ++row) {
int colCount = sheet->lastCol();
for(int col = 0; col <= colCount; ++col) {
csvFile << sheet->readStr(row, col).c_str();
if(col != colCount) {
csvFile << ",";
}
}
csvFile << endl;
}
csvFile.close();
}
}
}
}
book->release();
}
return 0;
}`
but i always get this eror:
undefined reference to xlCreateBook
Can you please tell me what to do to be recognized in my code?

Undefined reference means the linker cannot find the implementation of that function. To be more precise, you are not linking against libxl.
Check again that you made the linker related configurations properly and that all the required files are at the configured paths.
It would also be useful that you post the full compilation/build log.

Related

How do I limit the file size so my program creates a new file after it becomes too large? and edit the name of the newly created file?

As I run my code it builds the text file which quickly exceeds a size where I can effectively use it.
How would I set a size limit to the text size so that it creates a new text file with a title +1 of the previous file?
#include <iostream>
#include <vector>
#include <string.h>
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
void Crack(string password, vector<char> Chars)
{
ofstream myfile;
myfile.open ("pass.txt");
myfile<<"PASSWORDs TO CRACK: 0 to "<<password<<endl;
int n = Chars.size();
int i = 0;
while(true)
{
i++;
int N = 1;
for(int j=0;j<i;j++)N*=n;
for(int j=0;j<N;j++)
{
int K = 1;
string crack = "";
for(int k=0;k<i;k++)
{
crack += Chars[j/K%n];
K *= n;
}
myfile<< crack<<" "<<endl;
if(password.compare(crack) == 0){
myfile<<"Cracked password: "<<crack<<endl;
return;
myfile.close();
}
}
}
}
int main()
{
vector<char> Chars;
for(char c = '0';c<='z';c++){
if(islower(c) || isdigit(c))Chars.push_back(c);
}
Crack("zzzzzzzzzzzzzzzzzz", Chars);
}
You can use ostream::tellp to give you the current file size. If it exceeds the limit, close the stream and create a new file.
What do you mean by "title+1"? Do you mean the file name or do you want to print a header in each file?

Getting date and time from a .txt

I am trying to get the date and time from a file I have which is something like this
"Run01"
"‹L˜^’·","ŽžŠÔŽ²","Äضޓú•t","Äضގž"
"70000 DIV","100ms (1ms/S)","17-03-25","06:16:15.49"
"Á¬ÈÙ","±ÝÌß","“dˆ³Ž²","ºÒÝÄ","½¹°ØݸÞ","•ÏŠ·”ä","µÌ¾¯Ä","̨ÙÀ"
"CH1-1","8956 H-SPEED","200mV","Detector11","OFF","-","-","OFF"
"CH1-2","8956 H-SPEED","200mV","Detector12","OFF","-","-","OFF"
"CH2-1","8956 H-SPEED","200mV","Detector21","OFF","-","-","OFF"
"CH2-2","8956 H-SPEED","200mV","Detector22","OFF","-","-","OFF"
"CH3-1","8956 H-SPEED","200mV","Detector31","OFF","-","-","OFF"
"CH3-2","8956 H-SPEED","200mV","Detector32","OFF","-","-","OFF"
"CH4-1","8956 H-SPEED","200mV","Detector41","OFF","-","-","OFF"
"CH4-2","8956 H-SPEED","200mV","Detector42","OFF","-","-","OFF"
"ŽžŠÔ[s]","CH1-1[V]","CH1-2[V]","CH2-1[V]","CH2-2[V]","CH3-1[V]","CH3-2[V]","CH4-1[V]","CH4-2[V]"
where the date and time is located in line 3 after the 2 comma(,)
I'm a bit confused from the examples found on google. Anyone have any idea on how I might do this?
edit*I add some bit of what I done so far,
#include <iostream>
#include <fstream>
#include <string>
const int LINE = 4;
int draft(){
std::ifstream fdate("DataFile0001/DataFile_B0001_info.txt");
std::string s;
for (int i = 1; i<= LINE; i++)
std::getline(f,s);
std::cout << s;
return 0;
}
TO be honest I do not want to compile and run this but rather just root draft.cc as I am going to use it to process the root file I have. But as this is more of a c++ problem rather than root. asking here I think is more appropriate
for (int i = 1; i<= LINE; i++)
{
std::getline(f,s);
if(i == 3)
{
size_t pos = s.find_first_of(",");
pos = s.find_first_of("," , pos+1);
std::string date = s.substr(pos+2 , s.find_first_of("," , pos+1)-pos-3);
pos = s.find_first_of("," , pos+1);
std::string time = s.substr(pos+2 , s.length()-pos-3);
std::cout << date << std::endl;
std::cout << time << std::endl;
break;
}
}

C++ Dictionary Compare with multiple strings and files

I am trying to write a program that will compare an input file to a dictionary file filled with tons of words. After comparing the words, I want to output the words that are spelled incorrectly. Here is my code:
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <vector>
using namespace std;
void trim(string s)
{
size_t p = s.find_first_not_of(" \t");
s.erase(0, p);
p = s.find_last_not_of(" \t");
if (string::npos != p)
s.erase(p+1);
}
int main()
{
ifstream input;
ifstream words;
input.open("/Users/jordan/Desktop/CS60/Word_dictionary_check/input.txt");
if(input.fail())
{
cout<<"Input file opening failed";
exit(1);
}
words.open("/Users/jordan/Desktop/CS60/Word_dictionary_check/words.txt");
if(words.fail())
{
cout<<"Words file opening failed";
}
vector <string> wordCheck;
vector <string> misspelledWord;
string temp = "";
while(!input.eof())
{
input>>temp;
wordCheck.push_back(temp);
}
ofstream output;
output.open("/Users/jordan/Desktop/CS60/Word_dictionary_check/output.txt");
if(output.fail())
{
cout<<"Output file opening failed";
exit(1);
}
for(int j = 0; j < wordCheck.size(); j++)
{
bool dontprint = false;
while(!words.eof())
{
words>>temp;
if(temp == wordCheck[j])
{
dontprint = true;
}
}
if(dontprint == false)
{
misspelledWord.push_back(wordCheck[j]);
}
}
for(int i = 0; i < misspelledWord.size() ; i++)
{
output<<misspelledWord[i]<<endl;
}
return 0;
}
I believe something with whitespace or with the comparing of strings is a problem. Thanks for helping me out!
I can see few obvious problems. I have added comments. This should solve your problem but I am not going to write code for you.
for(int j = 0; j < wordCheck.size(); j++)
{
bool dontprint = false;
//Make your words file pointer to point to start of file. USe seek function
while(!words.eof())
{
words>>temp;
if(temp == wordCheck[j])
{
dontprint = true;
//You can break here. As once word is found, you don't need to check the word file further
}
}
if(dontprint == false)
{
misspelledWord.push_back(wordCheck[j]);
}
}

remove stopwords then apply case folding ( how to combine two codes)

I have a txt file called aisha includes this
This is a new file I did it for mediu.
Its about Removing stopwords fRom the file
and apply casefolding to it
I Tried doing that many Times
and finally now I could do
and I wrote two codes one is to remove some stop words from it
#include <iostream>
#include <string>
#include <fstream>
int main()
{
using namespace std;
ifstream file("aisha.txt");
if(file.is_open())
{
string myArray[200];
for(int i = 0; i < 200; ++i)
{
file >> myArray[i];
if (myArray[i] !="is" && myArray[i]!="the" && myArray[i]!="that"&& myArray[i]!="it"&& myArray[i]!="to"){
cout<< myArray[i]<<" ";
}
}
}
system("PAUSE");
return 0;
}
and the other is for apply casefolding for four ketters
#include <iostream>
#include <string>
#include <fstream>
int main()
{
using namespace std;
ifstream file("aisha.txt");
if(file.is_open())
{
file >> std::noskipws;
char myArray[200];
for(int i = 0; i < 200; ++i)
{
file >> myArray[i];
if (myArray[i]=='I')
cout<<"i";
if (myArray[i]=='A')
cout<<"a";
if (myArray[i]=='T')
cout<<"t";
if (myArray[i]=='R')
cout<<"r";
else
if (myArray[i]!='I' && myArray[i]!='T' && myArray[i]!='R')
cout<<myArray[i];
}
file.close();
}
system("PAUSE");
return 0;
}
now that I need to combine these two codes into one code that remove stopwords and then apply case folding
the problem that I used string myArray[200]; for the stopwords codeand char myArray[200]; for the case folding code
and I cant use only string or only char
what can I do ?
Put the text processors in separate functions and call them one by one in main. There will be no names and types collisions.
Here is rough example
void removeStopWords(ifstream file) {
// put your code here for removing the stopwords
}
void applyCaseFolding(ifstream file) {
// put your code here for applying case folding
}
int main() {
ifstream file("aisha.txt");
if(file.is_open()) {
removeStopWords(file);
applyCaseFolding(file);
}
return 0;
}

C++ Compiler Seemingly Skipping Line of Code

I am new to C++ programming and am obviously missing something. In the following code the compiler doesn't seem to recognize this line: lengths[counter] = findDups(crtLine); I get an error: variable "lengths" set but not used. I cannot figure out why it is not recognizing this line, when the names[counter] = getNameOnly(crtLine) works perfectly and it is essentially the same format. Any insight into this issue is appreciated!
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
using namespace std;
string getNameOnly (string line) {
return line.substr(0, line.find(' '));
}
int findDups (string line) {
string lnCpy = line;
sort(lnCpy.begin(), lnCpy.end());
int i = 0;
int dups = 0;
int j = 1;
int len = lnCpy.length();
while (j < len) {
if (lnCpy.at(i) == lnCpy.at(j))
dups++;
i++;
j++;
}
if (dups != 0)
return 0;
else
return lnCpy.length();
}
int main() {
string names[1219];
int lengths[1219];
string crtLine;
int counter = 0;
ifstream myfile ("dist.male.first");
if (myfile.is_open()) {
while (!myfile.eof()) {
getline(myfile,crtLine);
lengths[counter] = findDups(crtLine);
names[counter] = getNameOnly(crtLine);
counter++;
}
myfile.close();
}
else cout << "Unable to open file";
return (0);
}
That's a warning, not an error, and it tells you exactly what the problem is: you put things into the variable named lengths, but never check what's in it, you might as well never store anything there in the first place.
You don't get a similar warning for names, because the assignment operator of std::string has side effects, and the compiler assumes you were interested in the side effect (rather than getting the value out later).