-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetNameTest.cpp
More file actions
35 lines (32 loc) · 955 Bytes
/
getNameTest.cpp
File metadata and controls
35 lines (32 loc) · 955 Bytes
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
#include <limits.h>
#include <unistd.h>
#include <iostream>
#include <filesystem>
#include <vector>
#include <string>
#include <fstream>
namespace fs = std::filesystem;
using namespace std;
int main(int argc, char *argv[]) {
char hostyNamey[256];
getlogin_r(hostyNamey, sizeof(hostyNamey));
cout << hostyNamey << endl;
string hostName = string(hostyNamey);
string path = "/home/" + hostName + "/code/test";
vector<string> filesInDownloads;
for (const auto & entry : fs::directory_iterator(path))
filesInDownloads.push_back(entry.path().filename().string());
for (const auto & file : filesInDownloads) {
cout << file << endl;
}
cout << "Now let us try writing to a file" << endl;
string contents;
return 0;
}
// write to a file using ofstream
void writeToFile(const string & fileName, const string & data) {
ofstream file;
file.open(fileName);
file << data;
file.close();
}