//: S07:Text.cpp
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
class Text {
string text;
public:
Text() {}
Text(const string& fname) {
ifstream ifs(fname.c_str());
string line;
while (getline(ifs, line))
text += line + '\n';
}
string contents() {
return text;
}
};
int main(int argc, char* argv[]) {
if (argc > 1)
{
Text t1;
Text t2(argv[1]);
cout << "t1 :\n" << t1.contents() << endl;
cout << "t2 :\n" << t2.contents() << endl;
}
}
///:~
Kako god da prosledim ime neke datoteke kao argv[1] u kom.liniji, na izlazu dobijem samo
t1:
t2:
iako bi posle t2 trebalo da sledi sadrzaj doticne datoteke.
Posto je argument pointer, trbalo bi u kom.liniji da prosledim adresu fajla, ali kako ?
Kompajler je Dev-Cpp.
TX