1// extract to string
2#include <iostream>
3#include <string>
4
5int main ()
6{
7 std::string name;
8
9 std::cout << "Please, enter your full name: ";
10 std::getline (std::cin,name);
11 std::cout << "Hello, " << name << "!\n";
12
13 return 0;
14}
1//getline allows for multi word input including spaces ex. "Jim Barens"
2#include <iostream>
3#include <string>
4
5int main()
6{
7 string namePerson{}; // creating string
8 getline(cin, namePerson);// using getline for user input
9 std::cout << namePerson; // output string namePerson
10}
1SensorsFile::SensorsFile(const string fname, bool verbose)
2 : Sensors(fname, verbose){
3
4 // BEGIN: F2
5
6 ifstream inFile(fname);
7 if (!inFile) {
8 throw runtime_error("Could not read from file " + fname + '\n');
9 }
10
11 string line;
12 // auto dummy;
13
14 unsigned int timestep;
15 string dam; int inflow;
16 int outflow;
17 getline(inFile, line); // Denne for å fjerne første linje av filen!
18
19 // Her er det viktig å huske at vi må fjerne første linje, da denne kun er til info.
20 while (getline (inFile, line)) {
21 // stringstream ss;
22 string dummy;
23
24 getline(inFile, dummy, ',');
25 timestep = stoi(dummy);
26
27 getline(inFile, dummy, ',');
28 dam = dummy;
29
30 getline(inFile, dummy, ',');
31 inflow = stoi(dummy);
32
33 getline(inFile, dummy, ',');
34 outflow = stoi(dummy);
35
36 insert_reading(timestep, dam, inflow, outflow);
37 }
38
39 inFile.close();
40
41 // END: F2
42 }