---
title: "fstream-problem"
type: "forum-thread"
url: "https://www.webforum.nu/amne/c-cpp/102289-fstream-problem"
topic: "C/C++"
topic_url: "https://www.webforum.nu/amne/c-cpp"
author: "Tjock-Erik"
published: "2004-04-25T09:41:26.000Z"
updated: "2004-04-25T13:44:08.000Z"
replies: 1
views: 186
page: 1
pages: 1
language: "sv-SE"
site: "webForum — webforum.nu"
rights: "Upphovsrätten till varje inlägg tillhör dess författare."
attribution: "Citera som: webForum, https://www.webforum.nu/amne/c-cpp/102289-fstream-problem"
---

# fstream-problem

## #1 — Tjock-Erik, 2004-04-25T09:41Z

cout\<\<"Filnamn: ";
getline (cin, filnamn);
ofstream output("c:\\\\hej\\\\"\<\<filnamn\<\<".txt");
output\<\<"Hej";

Jag vill alltså skapa en fil med ett namn som jag tidigare själv anger genom att spara värdet i en sträng. Problemet är bara att något är fel på ofstream-raden. Vet någon hur detta ska skrivas i stället?

Permalänk: https://www.webforum.nu/p/102289

## #2 — Peter S, 2004-04-25T13:44Z

```
cout << "Filnamn: " << flush;
    
string filename;
getline(cin, filename);
    
const char* file = filename.c_str();
char buffer[80];
sprintf(buffer, "c:\\hej\\%s.txt", file);
    
ofstream output(buffer);
output << "Hej";
output.close();
```

 :)

Permalänk: https://www.webforum.nu/p/1330395

---

Tråden på webben: https://www.webforum.nu/amne/c-cpp/102289-fstream-problem
