1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include <iostream>
#include <fstream>
#include <iostream>
#include <string>
#include <iterator>
#include <sstream>
#include <vector>
#include <numeric>
using std::string;
using std::ifstream;
using std::ofstream;
using namespace std;
enum Greeting{
hello =1, goodbye
};
class testLine{
public:
testLine() : greeting{hello}, fruit{}, value1{}, value2{} {
}
testLine(Greeting g, string f,int v1,int v2): greeting{g}, fruit{f}, value1{v1}, value2{v2} {}
private:
Greeting greeting;
string fruit;
int value1{};
int value2{};
};
template<class T> T from_string(const string s) {
std::stringstream ss{s};
T val{};
if(!(ss>>val)) {
cerr<<"failed to convert from string";
}
return val;
}
template<class T> T dateiLesen(string file) {
ifstream is{file.c_str()};
std::istream_iterator<string> file_it{is};
std::istream_iterator<string> eof{};
T testl{};
while(file_it!= eof && is){
string greeting{*file_it};
file_it++;
string fruit{*file_it};
file_it++;
string val1{*file_it};
file_it++;
int v1{ from_string<int>(val1.substr(1, string::npos))};
string val2{*file_it};
file_it++;
int v2{ from_string<int>(val2.substr(1, string::npos))};
testLine t{ (greeting, fruit, v1, v2) }
testl.push_back(t);
return testl;
}
}
int main(int argc, char *argv[]) {
vector<testLine> test{dateiLesen<vector> > (test,"textfile.txt")};
return 0;
}
|
errors: filesbehandlung.cpp:65:16: warning: expression result unused [-Wunused-value]
testLine t{ (greeting, fruit, v1, v2) }
^~~~~~~~
filesbehandlung.cpp:65:26: warning: expression result unused [-Wunused-value]
testLine t{ (greeting, fruit, v1, v2) }
^~~~~
filesbehandlung.cpp:65:33: warning: expression result unused [-Wunused-value]
testLine t{ (greeting, fruit, v1, v2) }
^~
filesbehandlung.cpp:65:12: error: no matching constructor for initialization of 'testLine'
testLine t{ (greeting, fruit, v1, v2) }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
filesbehandlung.cpp:19:7: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'testLine' for 1st argument
class testLine{
^
filesbehandlung.cpp:19:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const testLine' for 1st argument
class testLine{
^
filesbehandlung.cpp:22:2: note: candidate constructor not viable: requires 0 arguments, but 1 was provided
testLine() : greeting{hello}, fruit{}, value1{}, value2{} {
^
filesbehandlung.cpp:24:2: note: candidate constructor not viable: requires 4 arguments, but 1 was provided
testLine(Greeting g, string f,int v1,int v2): greeting{g}, fruit{f}, value1{v1}, value2{v2} {}
^
filesbehandlung.cpp:65:42: error: expected ';' at end of declaration
testLine t{ (greeting, fruit, v1, v2) }
^
;
filesbehandlung.cpp:74:46: warning: expression result unused [-Wunused-value]
vector<testLine> test{dateiLesen<vector> > (test,"textfile.txt")};
^~~~
filesbehandlung.cpp:74:24: error: reference to overloaded function could not be resolved; did you mean to call it?
vector<testLine> test{dateiLesen<vector> > (test,"textfile.txt")};
^~~~~~~~~~~~~~~~~~
filesbehandlung.cpp:44:21: note: possible target for call
template<class T> T dateiLesen(string file) {
^
4 warnings and 3 errors generated.