回答編集履歴
6
ソース修正
test
CHANGED
@@ -42,11 +42,9 @@
|
|
42
42
|
|
43
43
|
```
|
44
44
|
|
45
|
-
追記の追記w rfind()使ってみた。
|
45
|
+
追記の追記w rfind()とsubstr()使ってみた。
|
46
46
|
|
47
47
|
usr ~/Project/test % ./a.out
|
48
|
-
|
49
|
-
~/Project/test/aaaa
|
50
48
|
|
51
49
|
~/Project/test/aaaa
|
52
50
|
|
@@ -56,15 +54,11 @@
|
|
56
54
|
|
57
55
|
#include <iostream>
|
58
56
|
|
59
|
-
#include <
|
57
|
+
#include <string>
|
60
58
|
|
61
59
|
int main(void)
|
62
60
|
|
63
61
|
{
|
64
|
-
|
65
|
-
std::filesystem::path p = "~/Project/test/aaaa.csv";
|
66
|
-
|
67
|
-
std::cout << p.parent_path().string<char>() << p.preferred_separator << p.stem().string<char>() << std::endl;
|
68
62
|
|
69
63
|
//
|
70
64
|
|
@@ -78,6 +72,4 @@
|
|
78
72
|
|
79
73
|
}
|
80
74
|
|
81
|
-
|
82
|
-
|
83
75
|
```
|
5
ソース追記
test
CHANGED
@@ -41,3 +41,43 @@
|
|
41
41
|
usr ~/Project/test %
|
42
42
|
|
43
43
|
```
|
44
|
+
|
45
|
+
追記の追記w rfind()使ってみた。
|
46
|
+
|
47
|
+
usr ~/Project/test % ./a.out
|
48
|
+
|
49
|
+
~/Project/test/aaaa
|
50
|
+
|
51
|
+
~/Project/test/aaaa
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
```c++
|
56
|
+
|
57
|
+
#include <iostream>
|
58
|
+
|
59
|
+
#include <filesystem>
|
60
|
+
|
61
|
+
int main(void)
|
62
|
+
|
63
|
+
{
|
64
|
+
|
65
|
+
std::filesystem::path p = "~/Project/test/aaaa.csv";
|
66
|
+
|
67
|
+
std::cout << p.parent_path().string<char>() << p.preferred_separator << p.stem().string<char>() << std::endl;
|
68
|
+
|
69
|
+
//
|
70
|
+
|
71
|
+
std::string path = "~/Project/test/aaaa.csv";
|
72
|
+
|
73
|
+
std::cout << path.substr(0,path.rfind('.')) << std::endl;
|
74
|
+
|
75
|
+
//
|
76
|
+
|
77
|
+
return 0;
|
78
|
+
|
79
|
+
}
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
```
|
4
ソース修正
test
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
追記
|
8
8
|
|
9
|
-
yumetodoさんの補足です。パスが有る場合も処理できます。
|
9
|
+
yumetodoさんの補足です。パスが有る場合も処理できます。
|
10
10
|
|
11
11
|
```text
|
12
12
|
|
@@ -28,7 +28,7 @@
|
|
28
28
|
|
29
29
|
std::filesystem::path p = "~/Project/test/aaaa.csv";
|
30
30
|
|
31
|
-
std::cout << p.parent_path().string<char>() <<
|
31
|
+
std::cout << p.parent_path().string<char>() << p.preferred_separator << p.stem().string<char>() << std::endl;
|
32
32
|
|
33
33
|
//
|
34
34
|
|
3
ソース追記
test
CHANGED
@@ -3,3 +3,41 @@
|
|
3
3
|
で見つけて、そこまでをsubstr()で取り出しましょう。
|
4
4
|
|
5
5
|
→ [std::basic_string::rfind](https://cpprefjp.github.io/reference/string/basic_string/rfind.html)
|
6
|
+
|
7
|
+
追記
|
8
|
+
|
9
|
+
yumetodoさんの補足です。パスが有る場合も処理できます。(UNIXのディレクトリ区切り'/'使っています)
|
10
|
+
|
11
|
+
```text
|
12
|
+
|
13
|
+
usr ~/Project/test % c++ t1.cpp
|
14
|
+
|
15
|
+
usr ~/Project/test % ./a.out
|
16
|
+
|
17
|
+
~/Project/test/aaaa
|
18
|
+
|
19
|
+
usr ~/Project/test % cat t1.cpp
|
20
|
+
|
21
|
+
#include <iostream>
|
22
|
+
|
23
|
+
#include <filesystem>
|
24
|
+
|
25
|
+
int main(void)
|
26
|
+
|
27
|
+
{
|
28
|
+
|
29
|
+
std::filesystem::path p = "~/Project/test/aaaa.csv";
|
30
|
+
|
31
|
+
std::cout << p.parent_path().string<char>() << '/' << p.stem().string<char>() << std::endl;
|
32
|
+
|
33
|
+
//
|
34
|
+
|
35
|
+
return 0;
|
36
|
+
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
usr ~/Project/test %
|
42
|
+
|
43
|
+
```
|
2
誤記修正
test
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
fileName.rfind(
|
1
|
+
fileName.rfind('.');
|
2
2
|
|
3
3
|
で見つけて、そこまでをsubstr()で取り出しましょう。
|
4
4
|
|
1
追記
test
CHANGED
@@ -1,3 +1,5 @@
|
|
1
1
|
fileName.rfind(".");
|
2
2
|
|
3
3
|
で見つけて、そこまでをsubstr()で取り出しましょう。
|
4
|
+
|
5
|
+
→ [std::basic_string::rfind](https://cpprefjp.github.io/reference/string/basic_string/rfind.html)
|