-
ifstream and ofstream
I'm reading this tutorial:
http://www.cprogramming.com/tutorial/lesson10.html
I have found this a little bit challenging. Can anyone expound to me what it means technically.
I'm a python programmer and would like to add C++ and take advantage of ctypes and also I learn myself.
Thanks for your help.
-
So, could you be a bit more specific as to which part of the tutorial you do not understand?
--
Mats
-
How good are you with cin and cout? File streams are supposed to work pretty much exactly the same way.
-
In python it is as simple as:
fo = open("steve.txt")
for words in fo:
print words
it will print all words in text files. I was wondering how easy it is in C++ :confused:
-
Soma
Code:
#include <fstream>
#include <iostream>
int main()
{
return(!(std::cout << std::ifstream("test.cxx").rdbuf()));
}
-
Well, that is the equivalent of
Code:
print open("test.cxx").read()
in Python.
Use getline(input_stream_object, string_object) to read a line of input, just as you would do with cin.
Code:
ifstream fin("test.cxx");
std::string line;
while (std::getline(fin, line)) {
std::cout << line << '\n';
}
-