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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:15:28+00:00 2026-06-12T07:15:28+00:00

So I tried to do this: #include <iostream>//For cout/cin #include <fstream> //For ifstream/ofstream using

  • 0

So I tried to do this:

#include <iostream>//For cout/cin
#include <fstream> //For ifstream/ofstream

using namespace std;

int main()
{
    string types[] = {"Creativity", "Action", "Service"};
    for(int i = 0; i < sizeof(types)/sizeof(string); i++) {
        string type = types[i];
        string filename = type + ".html";
        ofstream newFile(filename);
        //newFile << toHTML(getActivities(type));
        newFile.close();
    }
    return 0;
}

and I’m being hit with errors. I’m new to C++, so I don’t know what to try, or if this is even possible (SURELY it is…).
I tried the following, but it was really just a stab in the dark and didn’t help:

#include <iostream>//For cout/cin
#include <fstream> //For ifstream/ofstream

using namespace std;

int main()
{
    string types[] = {"Creativity", "Action", "Service"};
    for(int i = 0; i < sizeof(types)/sizeof(string); i++) {
        string type = types[i];
        //Attempting to add const..
        const string filename = type + ".html";
        ofstream newFile(filename);
        //newFile << toHTML(getActivities(type));
        newFile.close();
    }
    return 0;
}

I mean, its all happy if I do `ofstream newFile(“somefile.html”);

  • 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-06-12T07:15:29+00:00Added an answer on June 12, 2026 at 7:15 am

    The original IOstream library didn’t have a constructor taking a std::string. The only type supported was char const*. You can get a char const* from a std::string using c_str():

    std::string name("whatever");
    std::ofstream out(name.c_str());
    

    The type of a string literal isn’t of type std::string but it is of type char const[n] where n is the number of characters in the string, including the terminating null character.

    In C++ 2011 the File stream classes are improved to also take std::string where a string is expected.

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

Sidebar

Related Questions

Given this code: #include <cstdio> #include <iostream> #include <string> using std::cin; using std::cout; using
#include<iostream> #include<string.h> #include<algorithm> using namespace std; pair<char[300],int> list[10000]; int main() { char a[300],b[20000]; int
#include <iostream> #include <string> using namespace std; int main() { double age; double months;
//Testing numbers for primality #include <iostream> #include <cmath> using namespace std; int main() {
#include <iostream> #include <ctype.h> using namespace std; void isPalindrome(); int main() { char response;
#include <iostream> #include randword.h #include <fstream> #include <time.h> #include <cstdlib> using namespace std; bool
#include <iostream> using namespace std; struct Node { int item; // storage for the
#include <iostream> using namespace std; struct Node { int item; // storage for the
I wrote the following program using VS2008: #include <fstream> int main() { std::wofstream fout(myfile);
#include <iostream> using namespace std; class Exem { int *a; public: Exem() { a

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.