dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 21

Thread: [RESOLVED] Database creation

  1. #1
    Join Date
    Mar 2017
    Posts
    105

    [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.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,562

    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

  3. #3
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,924

    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++17 Compiler: Microsoft VS2019 (16.4.0)

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,555

    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.

  5. #5
    Join Date
    Mar 2017
    Posts
    105

    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.

  6. #6
    Join Date
    Mar 2017
    Posts
    105

    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.

  7. #7
    Join Date
    Mar 2017
    Posts
    105

    Re: Database creation

    Is office open XML right..?

  8. #8
    Join Date
    Jun 2003
    Location
    Armenia, Yerevan
    Posts
    720

    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.
    Popular opinion is the greatest lie in the world.

  9. #9
    Join Date
    Mar 2017
    Posts
    105

    Re: Database creation

    Thanks, can you help me with the code.

  10. #10
    Join Date
    Jun 2003
    Location
    Armenia, Yerevan
    Posts
    720

    Re: Database creation

    No, there are lots of samples available in the internet.
    Popular opinion is the greatest lie in the world.

  11. #11
    Join Date
    Mar 2017
    Posts
    105

    Re: Database creation

    Fine bro, thanks .
    Last edited by A_Singh; January 5th, 2018 at 03:08 AM.

  12. #12
    Join Date
    Mar 2017
    Posts
    105

    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)

  13. #13
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,562

    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

  14. #14
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,924

    Re: Database creation

    Quote Originally Posted by A_Singh View Post
    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++17 Compiler: Microsoft VS2019 (16.4.0)

  15. #15
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    6,924

    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++17 Compiler: Microsoft VS2019 (16.4.0)

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)