Mam taki kod jak go zmodyfikować, żeby zapisywał do pliku, nie dopisywał (app)??
#include<iostream>
#include<algorithm>
#include<conio.h>
#include <fstream>
#include<string>
#include <sstream>
using namespace std;
const char d = 'A' - 'a';
char toUpper(char c)
{
if ('a' <= c && c <= 'z') return c + d;
else return c;
}
using namespace std;
int main()
{
string s;
fstream plik;
plik.open("dane.txt", ios::in);
if (plik.good())
{
string napis;
do
{
getline(plik, napis);
transform(napis.begin(), napis.end(), napis.begin(), ::toupper);
cout << napis;
s = napis;
;
fstream plik("plik.txt", ios::app);
if (plik.good())
{
plik <<s<<endl;
plik.close();
}
plik.close();
} while (!plik.eof());
}
else cout << "Error! Nie udalo otworzyc sie pliku!" << endl;
_getch();
}
Jak daje "out" to mam znów pusty plik, nie wiadomo dlaczego.
PS: A jak dam taki kod:
fstream plik("plik.txt", ios::out);
if (plik.good())
{
string test = "test";
plik <<s<<endl;
plik << test;
plik.close();
}
To stworzy nowy plik, pierwszej linijki nie zapisze, a tego stringa test już tak, dlaczego?
usunięcie pustego cytatu
- @furious programming