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

  • SEARCH
  • Home
  • 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 7600787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:59:52+00:00 2026-05-30T22:59:52+00:00

I write to a text file like so: void writeText(char* desc){ FILE * pFile;

  • 0

I write to a text file like so:

void writeText(char* desc){
    FILE * pFile;
    pFile = fopen ("CycleTestInfo.txt","a+");
    fputs (desc,pFile);
    fclose(pFile);
}

I embed this in a for loop and I want to write to the file the loop that I am on:

for(int i=0; i<cycles; i++){
    char* cycle="--NEW CYCLE "+(char)i+"---\r\n";
    writeText(cycle);
}

However, I get error C2110: '+' : cannot add two pointers at the line where I declare cycle. How can I declare the the variable so that I can include the cycle number, i and also add a string to both sides?

Thanks for the help!

  • 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-30T22:59:54+00:00Added an answer on May 30, 2026 at 10:59 pm

    That’s not how you concatenate strings in C++.

    You can either use sprintf or std::string.

    The latter is more C++-ish::

    std::string cycle("--NEW CYCLE");
    cycle += (char)i;
    cycle += "---\r\r";
    
    writeText(cycle.c_str();
    

    Note that you must also change the function signature to:

    void writeText(const char* desc)
    

    since string::c_str() returns a const char*.

    Or you could use a stringstream, but that’s a bit of overkill in this case. Worth looking into it though.

    The reason you’re getting an error is that "--NEW CYCLE " is a const char* in C++, not a std::string.

    You could edit your line to work:

    const char* cycle= (std::string("--NEW CYCLE ")+(char)i+"---\r\n").c_str();
    

    but I wouldn’t do that. It looks ugly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to write text to my txt file. After the first write
I'm writing some strings to a file using the following function... void writeText(const char*
Using Apache POI HSSF, we can create xls file like this private void write(HSSFWorkbook
Which is the fast way to write text file in java? At the moment
How can I get Mathematica to export/save/write a text file with proper Fortan77 formatting,
I have a GUID variable and I want to write inside a text file
I'm trying to find a way to write to a text file from as2.
Let's say I have a program to write text into a file (not really
How can I write text entities to a dxf file? I found a script
I want to write JSON data to a text file using jQuery and PHP.

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.