-
January 4th, 2018, 09:22 AM
#1
[RESOLVED] Database creation
What my problem is that I need to create a database with all types of formats (underlined text, bolt text, italics text, bolt borders, etc..But the problem is that a .csv file doesn't support all these. If I create a spreadsheet, for all these purposes, excel shows them as corrupt, after editing using c++. What my basic code does is copies the exact content of one file to another, here is the code:
Code:
#include <iostream>
#include <conio.h>
#include <string>
#include <fstream>
using namespace std;
string line;
int main()
{
ifstream inputFile;
ofstream outputFile;
inputFile.open("Hello.csv");
outputFile.open("Hello1.csv");
if (inputFile.is_open() && outputFile.is_open())
{
while (getline(inputFile, line))
{
outputFile << line << endl;
}
}
else
{
cout << "File not found" << endl;
}
return 0;
}
If there are any parts in the code, which make the file corrupt, please suggest changes.
If no, please suggest any other format of an excel file, which can be edited by c++.
Thanks for any answers and help in advance.
-
January 4th, 2018, 10:33 AM
#2
Re: Database creation
1. Use the .xls or .xlsx format (as already suggested in some of your other thread).
2. To edit these file types from C++ code you should use Excel Automation. Search MSDN for details.
Victor Nijegorodov
-
January 4th, 2018, 12:09 PM
#3
Re: Database creation
is copies the exact content of one file to another
No it doesn't. It copies a text file (non-raw or 'cooked') to another file assuming that \n is the line termination character(s). If the input file is not a text file, then this method of file copying won't work.
What is the format of hello.csv? Can you attach a sample that the code in post #1 corrupts?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
January 4th, 2018, 01:13 PM
#4
Re: Database creation
It would help if you were consistent with your terms. There's nothing in your post that has to do with database creation, and nothing in your code that edits anything. Saying a file becomes corrupt when you edit it with C++ doesn't tell us anything useful that we could provide help for. Also, a CSV file isn't really a database.
-
January 4th, 2018, 08:14 PM
#5
Re: Database creation
I'll surely attach my file, but see I am asking for a good file format to create a database which can even be edited by c++, and that's what I have mentioned in my topic.
-
January 4th, 2018, 08:19 PM
#6
Re: Database creation
And I'd be really pleased if you tell what can be a 'better' way of copying a CSV file to another.
-
January 4th, 2018, 09:09 PM
#7
Re: Database creation
Is office open XML right..?
-
January 5th, 2018, 01:52 AM
#8
Re: Database creation
And I'd be really pleased if you tell what can be a 'better' way of copying a CSV file to another.
This could be accomplished using file mapping or with just filling file's content into memory then dump modified data into output file.
The same thing is proposed in another thread, but it does copying line-by-line which could be inefficient for large .csv files.
-
January 5th, 2018, 02:12 AM
#9
Re: Database creation
Thanks, can you help me with the code.
-
January 5th, 2018, 02:20 AM
#10
Re: Database creation
No, there are lots of samples available in the internet.
-
January 5th, 2018, 02:28 AM
#11
Re: Database creation
Last edited by A_Singh; January 5th, 2018 at 03:08 AM.
-
January 5th, 2018, 03:09 AM
#12
Re: Database creation
I have checked the internet, found some of them, also I’d be thankful if you can send me the link of one such sample(whenever you have time)
-
January 5th, 2018, 03:44 AM
#13
Re: Database creation
What kind of database do you mean? Excel database? Or Ms Access one? Or some other database?
Anyway, you should access this database from your c++ code via some tools developed to work with databases. Such as ODBC classes or ODBC API, or via ADODB, or OLE consumer classes or ...
Victor Nijegorodov
-
January 5th, 2018, 03:49 AM
#14
Re: Database creation
Originally Posted by A_Singh
I'll surely attach my file, but see I am asking for a good file format to create a database which can even be edited by c++, and that's what I have mentioned in my topic.
Have you looked at using existing databases like mySQL (https://www.mysql.com/products/community/), Microsoft SQL (https://www.microsoft.com/en-us/down....aspx?id=42299) etc? These can be easily used from c++.
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
-
January 5th, 2018, 03:49 AM
#15
Re: Database creation
I'll surely attach my file
Where?
All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!
C++23 Compiler: Microsoft VS2022 (17.6.5)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|