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 6668973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:05:54+00:00 2026-05-26T03:05:54+00:00

I have built a .cpp program in order to write some content to a

  • 0

I have built a .cpp program in order to write some content to a .txt file created within the .cpp file.

I manage to write the desired content, however, when I am trying to open the created file from terminal, it says that it cannot find it although it is there.

When I try to open it with vi or nano it’s content it’s empty. It is like creating a new file.

However, when I open it outside terminal, I can see its content as I wanted.

What could be the problem and how can I fix this situation?

Bellow, I have added the code.

The problem is with the system(buffer) command. I receive the following error: sh: cannot open video2.txt: No such file. I have tried to opened the files from command prompt and I get the above described situation.

int main(int argc,char* argv[])
{

fstream RawStipFile;
RawStipFile.open(strcat(argv[1],".txt"));
string line;

if (RawStipFile.is_open())
{

    getline(RawStipFile, line);
    int i = 0;
    ofstream OutVideoStip;
    ofstream VideoList;
    VideoList.open("VideoList.txt");
    while ( RawStipFile.good() )
    {

        getline (RawStipFile,line);
        char* l;
        l = (char*) malloc(sizeof(char));
        l[0]=line[0];
        //cout<<line[0]<<endl;
        if (line[0]==35)
        {

            if (OutVideoStip.is_open())
            {
                OutVideoStip.close();
            }
            i++;
                        //char* base;
                        //base = (char*) malloc(1000*sizeof(char));
                        //sprintf(base, "%d", i);
            char* b;
            b = &line[1];
            VideoList<<b<<endl;
            OutVideoStip.open(strcat(b, ".txt"));


        }

        else
        {

            OutVideoStip << line << endl;

        }


    }

    OutVideoStip.close();
    RawStipFile.close();
    VideoList.close();
}

else
{
    cout << "Unable to open file \n";
}

fstream VideoNames;
VideoNames.open("VideoList.txt", fstream::in);

if (VideoNames.is_open())
{
    while ( VideoNames.good() )
    {
        getline(VideoNames, line);
        line=line.substr(1,line.length());
        if (line.compare(""))
        {
            string initial = "./txt2mat<";
            initial.append(line);
            initial.append(".txt>");
            initial.append(line);
            initial.append(".dat");
            cout<<initial<<endl;
            const  char* buffer;
            buffer = initial.c_str();
            system(buffer);
        }
    }
}
else
{
    cout<<"Unable to open file. \n";
}

VideoNames.close();

return 0;
}
  • 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-26T03:05:55+00:00Added an answer on May 26, 2026 at 3:05 am

    You are using strcat in a wrong way. I don’t know if that’s the cause of your problem, but it can result in undefined behavour;

    int main(int argc,char* argv[])
    {
        fstream RawStipFile;
        RawStipFile.open(strcat(argv[1],".txt"));
    

    Here you modify argv[1]. You append 4 characters to it, without allocating any memory.

    string line;
    ...
    char* b;
    b = &line[1];
    VideoList<<b<<endl;
    OutVideoStip.open(strcat(b, ".txt"));
    

    a string takes care of it’s own memory management. You can’t asume it has reserved 4 more bytes for you to append. If you need to append, use string member functions, not strcat.

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

Sidebar

Related Questions

I have a sample program in a file called helloworld.cpp: #include <iostream> using namespace
I have tried to write my first Boost program from information on the Boost
I have a number of projects created in VC++ 2008. However I'm getting the
I have a .lib file created with previous versions of visual studio, perhaps 2003
I have built an MSI that I would like to deploy, and update frequently.
I have built a simple C#.Net app on a M/C with only .Net FX
I have built a web page which contains a Crystal Report built using the
I have built an application in C# that I would like to be optimized
I have built a number of asp.net servercontrols into a class library, & I
I have built a .dll under WinXP that claims it can't find DWMAPI.DLL when

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.