code: добавлено получение аргументов команды

main
EvdochenkoNV 4 недель назад
Родитель 5c80c670c0
Сommit 07f4e26326

1
.gitignore поставляемый

@ -5,3 +5,4 @@
/main.exe /main.exe
/main.o /main.o
/unittest.layout /unittest.layout
/curl

@ -31,7 +31,12 @@
<Compiler> <Compiler>
<Add option="-Wall" /> <Add option="-Wall" />
<Add option="-fexceptions" /> <Add option="-fexceptions" />
<Add directory="curl/include" />
</Compiler> </Compiler>
<Linker>
<Add library="curl/lib/libcurl.dll.a" />
<Add directory="curl/lib" />
</Linker>
<Unit filename=".gitignore" /> <Unit filename=".gitignore" />
<Unit filename="histogram.cpp" /> <Unit filename="histogram.cpp" />
<Unit filename="histogram.h" /> <Unit filename="histogram.h" />

@ -1,30 +1,77 @@
#include <curl/curl.h>
#include "histogram.h" #include "histogram.h"
#include "text.h" #include "text.h"
#include "svg.h" #include "svg.h"
#include <iostream>
#include <vector>
#include <string>
using namespace std;
struct Input { struct Input {
vector<double> vec; vector<double> vec;
size_t korz{}; size_t korz{};
}; };
Input input_data(istream& in, bool prompt = false) { Input input_data(istream& in, bool promt = false) {
Input lin; Input lin;
size_t n, korz;
if(prompt) size_t number_count;
cerr << "Number of elements: "; if( promt ) {
in >> n; cerr << "Enter number count: ";
lin.vec.resize(n); }
for (size_t i = 0; i < n; i++) in >> number_count;
lin.vec.resize(number_count);
for (size_t i = 0 ; i < number_count ; i++) {
in >> lin.vec[i]; in >> lin.vec[i];
if(prompt) }
if( promt ) {
cerr << "Enter bin count: "; cerr << "Enter bin count: ";
}
in >> lin.korz; in >> lin.korz;
return lin; return lin;
} }
int main() { int main(int argc, char* argv[]) {
auto in = input_data(cin, true); if(argc > 1) {
cout << "argc = " << argc << endl;
for(int i = 0; i < argc; i++){
cout << "argv[" << i << "] = " << argv[i] << endl;
}
return 0;
}
curl_global_init(CURL_GLOBAL_ALL);
auto in = input_data(cin);
auto bins = make_histogram(in.korz, in.vec); auto bins = make_histogram(in.korz, in.vec);
show_histogram_svg(bins); show_histogram_svg(bins);
} }
//Ïîëó÷åíèå àðãóìåíòîâ êîìàíäû. Ñóòü â òîì, ÷òî êàæäûé àðãóìåíò (ïîòîê ñèìâîëîâ) èìååò ñâîé ïîðÿäêîâûé íîìåð.
//×òîáû ïðîãðàììà ìîëãà âîñïðèíèìàòü àðãóìåíòû è êîìàíäû òàê, êàê íàäî, àðãóìåíòû, êàê è ñëîâà â ëþáîì ÿçûêå, ðàçäåëÿþòñÿ ïðîáåëàìè.
// íàøåì ñëó÷àå ïðîãðàììà ïîêàçûâàåò, êàêîé ïîðÿäêîâûé íîìåð èìååò êàæäîå ñëîâî ñ ïîìîùüþ ïðîáåëîâ.
//Äëÿ NUL íè÷åãî íå âûâåäåòñÿ òàê êàê ìû âûâåëè èòîãîâûé ïîòîê â íèêóäà.
/*
C:\Users\Natasha\Desktop\Ïðîãè Ñ2\cs-lab34\bin\Debug>cs-lab34.exe -x --y /z w
argc = 5
argv[0] = cs-lab34.exe
argv[1] = -x
argv[2] = --y
argv[3] = /z
argv[4] = w
C:\Users\Natasha\Desktop\Ïðîãè Ñ2\cs-lab34\bin\Debug>cs-lab34.exe param "with spaces"
argc = 3
argv[0] = cs-lab34.exe
argv[1] = param
argv[2] = with spaces
C:\Users\Natasha\Desktop\Ïðîãè Ñ2\cs-lab34\bin\Debug>cs-lab34.exe param <marks.txt >NUL
*/

Загрузка…
Отмена
Сохранить