質問編集履歴

1

サンプルコードではなく実際に使用しているソースコードを省略した物に差し替え

2018/11/19 09:18

投稿

yoshiki0424yi
yoshiki0424yi

スコア12

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,9 @@
2
2
 
3
3
  あるソースコードにて指定した位置で別のソースコードの操作を走らせたいです.
4
4
 
5
- 簡単なサンプルコードを記載するのでこの場合はどう記述すればよいのかをご教授願いたいです.
5
+ 現在頭を悩ませているコードを記載するのでこの場合はどう記述すればよいのかをご教授願いたいです.
6
+
7
+ 開発環境はLinux OS で vscodeを利用し開発しています.
6
8
 
7
9
 
8
10
 
@@ -14,70 +16,174 @@
14
16
 
15
17
  ### 該当のソースコード
16
18
 
19
+ main.cpp
20
+
17
21
  ```c++
18
22
 
23
+ #include <gtkmm/application.h>
24
+
25
+
26
+
19
- #include <stdio.h>
27
+ #include "MyWindow.h"
20
28
 
21
29
 
22
30
 
23
- int main(void)
31
+ int main( ){
24
32
 
25
- {
33
+ auto app = Gtk::Application::create( );
26
34
 
27
- int a = 1;
35
+ ClusteringDataApp::MyWindow myWindow;
28
36
 
29
- int b = 2;
37
+
30
38
 
31
- int c = 3;
32
-
33
-
34
-
35
- c += a + b;
36
-
37
-
38
-
39
- /* ここで別ソースコードを実行 */
40
-
41
-
42
-
43
- printf("%d", c);
39
+ return app->run( myWindow );
44
-
45
-
46
-
47
- return 0;
48
40
 
49
41
  }
50
42
 
51
43
  ```
52
44
 
45
+ 以下コードの保存処理時に
53
46
 
47
+ MyWindow.cpp
54
48
 
55
49
  ```c++
56
50
 
57
- #include <stdio.h>
51
+ #include "MyWindow.h"
58
52
 
59
- int main(void)
60
53
 
61
- {
62
54
 
55
+ namespace ClusteringDataApp{
56
+
57
+ void MyWindow::on_saveButton_clicked( ){
58
+
59
+ const std::string fileName = "newData.txt";
60
+
61
+ std::cerr << data_.size( ) << " data is written to " << fileName << "\n";
62
+
63
+
64
+
65
+ auto ofs = std::ofstream( fileName, std::ios::out );
66
+
67
+ if( ofs.good( ) )
68
+
69
+ for( const auto& pair : data_ )
70
+
71
+ ofs << pair.first << "\t" << pair.second << "\n";
72
+
73
+ ofs.close( );
74
+
75
+
76
+
63
- c *= -1.0;
77
+ hide( );
78
+
79
+ }
80
+
81
+ }
82
+
83
+
84
+
85
+ ```
86
+
87
+ MyWindow.h
88
+
89
+ ```h
90
+
91
+ #ifndef MYWINDOW_INCLUDED
92
+
93
+ #define MYWINDOW_INCLUDED
94
+
95
+ #include <gtkmm/window.h>
96
+
97
+ #include <gtkmm/button.h>
98
+
99
+ #include <gtkmm/hvbox.h>
100
+
101
+ #include <gtkmm/filechooserdialog.h>
102
+
103
+ #include <gtkmm/stock.h>
104
+
105
+ #include <gtkmm/filefilter.h>
106
+
107
+ #include <giomm.h>
108
+
109
+
110
+
111
+ #include <iostream>
112
+
113
+ #include <vector>
114
+
115
+ #include <utility> // std::pair
116
+
117
+ #include <fstream>
118
+
119
+ #include <string>
120
+
121
+ #include <sstream>
122
+
123
+
124
+
125
+ #endif
126
+
127
+ ```
128
+
129
+ 以下のコードを走らせた後に保存処理が実行されるようにしたい.
130
+
131
+ ```cpp
132
+
133
+ #include <iostream>
134
+
135
+ #include <cstdlib>
136
+
137
+ #include <cmath>
138
+
139
+ #include <vector>
140
+
141
+ #include <utility>
142
+
143
+ #include <algorithm>
144
+
145
+ #include <random>
146
+
147
+
148
+
149
+ #include <Eigen/Dense>
150
+
151
+
152
+
153
+ template <typename T = double >
154
+
155
+ using dataType = std::vector< std::pair<T, T> >;
156
+
157
+
158
+
159
+ void showAll( dataType<>& );
160
+
161
+ void normalize( dataType<>& );
162
+
163
+
164
+
165
+ int main(){...
166
+
167
+ }
168
+
169
+
170
+
171
+ void showAll( dataType<>& data ){...
172
+
173
+ }
174
+
175
+
176
+
177
+ void normalize( dataType<>& data ){...
64
178
 
65
179
  }
66
180
 
67
181
  ```
68
182
 
69
-
70
-
71
183
  ### 補足情報
72
184
 
73
- 意味がわかにくかと思うので説明をさせていただくと,
185
+ 受けたコードをじっていて,別で行いい処理を記述したコードを作成したので
74
186
 
75
- 記述ソースの上のコード内に有る/* ここで別ソースコードを実行 */
76
-
77
- と記載しているところに,下コードを読み込んで実行し,実行した結果を
78
-
79
- コードのprintfで表示させたいということです.
187
+ 譲り受けたコードに搭載させるこはできな考えたためです.
80
-
81
-
82
188
 
83
189
  ご教授の方よろしくお願いいたします.