This repository has been archived by the owner on Jun 16, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42c04c2
commit 9f8b321
Showing
11 changed files
with
186 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
azzo | ||
mazzo | ||
pazzo | ||
seconda | ||
scruttira | ||
su file | ||
questa | ||
è la terza | ||
direi sia abbastanza |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int i; | ||
cout << "Immettere un numero: "; | ||
while (!(cin>>i)) { | ||
if (cin.eof()) | ||
break; | ||
cin.clear(); | ||
cin.ignore(); // scarta carttere successivo | ||
// posso scartare una riga intera con cin.igonre(srd::numeric_limits<std::streamsize>::max(), '\n'); | ||
} | ||
|
||
// sono riuscito a leggere un numero oppure è arrivato eof | ||
if (cin.eof()) { | ||
cerr << "Lettura fallita" << endl; | ||
return 1; | ||
} | ||
else { | ||
cout << "Numero letto: " << i << endl; | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ciao |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
a | ||
asdfa | ||
sdf asf | ||
abba | ||
abba azzo | ||
ozzo lollo | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
char c; | ||
ofstream f("redirect.txt"); | ||
if (!f) { | ||
cerr << "Errore apertura"; | ||
return 1; | ||
} | ||
cin >> noskipws; | ||
while (cin >> c) | ||
f << c; | ||
f.close(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
|
||
using namespace std; | ||
|
||
const char filename[] = "redirect.txt"; | ||
|
||
int main() { | ||
char c; | ||
ofstream fo(filename); | ||
|
||
if (!fo) { | ||
|
||
cerr << "Errore apertura"; | ||
return 1; | ||
} | ||
|
||
cin >> noskipws; | ||
while (cin >> c) | ||
fo << c; | ||
|
||
fo.close(); | ||
|
||
ifstream fi(filename); | ||
|
||
if (!fi) { | ||
cerr << "Errore apertura file in lettura"; | ||
return 1; | ||
} | ||
|
||
fi >> noskipws; | ||
while (fi >> c) | ||
cout << c; | ||
|
||
fi.close(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
char c; | ||
cin >> noskipws; | ||
while (cin >> c) | ||
cout << c; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
int main() { | ||
int i, somma = 0; | ||
while (cin >> i) { | ||
somma += i; | ||
} | ||
cout << "Stato cin: " << !(!cin) << endl; | ||
cout << "Raggiunto EOF? " << cin.eof() << endl; | ||
cout << "Pulizia cin" << endl; cin.clear(); | ||
cout << "Stato cin: " << !(!cin) << endl; | ||
cout << "Raggiunto EOF? " << cin.eof() << endl; | ||
cout << "Somma: " << somma << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
|
||
using namespace std; | ||
|
||
bool scrivi(ostream &s, const char *str) { | ||
if (!s) { | ||
cerr << "Errore nell'apertura"; | ||
return 1; | ||
} | ||
|
||
s << str; | ||
|
||
return static_cast<bool>(s); | ||
} | ||
|
||
int main() { | ||
ofstream f("out.txt"); | ||
scrivi(f, "ciao\n"); | ||
scrivi(cout, "ciao\n"); | ||
f.close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <iostream> | ||
#include <cstdlib> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
int i; | ||
cout << "Azz "; system("sleep 2"); cin >> i; // sync i/o | ||
|
||
for (int i=0; i<1000; i++) cout << "mazzopazzolazzo "; // scrittura chunk e riempimento buffer | ||
|
||
system("sleep 2"); | ||
|
||
cout << " Endline in arrivo " << endl; // '\n' alla fine dello stream di byte | ||
|
||
cout << " Flush forzato " << flush; | ||
|
||
cout << " Terminazione naturale"; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
const char filename[] = "append.txt"; | ||
fstream f(filename, ios_base::app); | ||
if (!f) { | ||
cerr << "errore apertura file"; | ||
return 1; | ||
} | ||
cin >> noskipws; | ||
char c; | ||
while (cin >> c) | ||
f << c; | ||
f.close(); | ||
return 0; | ||
} |