Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7584545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:56:55+00:00 2026-05-30T18:56:55+00:00

Just a syntax question, here is my code snippet. (Sorry, browser isn’t letting me

  • 0

Just a syntax question, here is my code snippet. (Sorry, browser isn’t letting me paste properly into stack overflow.)

#include <iostream>     /* 'iostream.h' is deprecated. */
#include <cstring>
#include <cstdlib>
#include <cstdio>

using namespace std;    /* Required. */

FILE *OpenFile(char *Filename)
{
        FILE *FP;

        if((FP = fopen(Filename, "r")) == NULL)
        {       /* Error opening file. */
                std::cout << "[!!] Unable to open database!"
                          << " Are you sure it exists?\n"
                          << "[<<] Database Unchanged.\n";
                exit(EXIT_FAILURE);     /* End program. */
        }

        else    /* Properly opened the file. */
                return FP;
}

int main(void)
{
        FILE *Data;     /* Our database file pointer. */
        Data = OpenFile("Data.txt");
        printf("Success!\n");
        return 0;
}

When I compile, I get the following warning:

$ g++ test.cpp -o test
test.cpp: In function ‘int main()’:
test.cpp:27:28: warning: deprecated conversion from string constant to ‘char*’ [-Wwrite-strings]
$

Where am I going wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:56:56+00:00Added an answer on May 30, 2026 at 6:56 pm

    String literals in C++ are of type “array of n const char” (where n is the number of characters in the string, including the terminating NUL). Declare your function this way:

    FILE *OpenFile(const char *Filename)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im struggling with syntax here: hopefully this question is v simple, im just miising
Models (disregard typos / minor syntax issues. It's just pseudo-code): class SecretModel(models.Model): some_unique_field =
Basic question here, can I put String variables into a position in a string
Should be a simple question, I'm just not familiar with PHP syntax and I
Using Python 3, I unpackaged the flufl.enum code into my application source tree just
Probably it is just a question of proper syntax. I use the animateWithDuration:delay:options:animations:completion: UIView
I just came over this syntax in some of the questions in this forum,
I'm looking for an editor - not an IDE - that has just syntax
I have just stumbled upon the bash syntax: foo=42 bar=$[foo+1] # evaluates an arithmetic
I was just trying to learn the syntax of the beginner things, and how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.