Форум программистов, компьютерный форум, киберфорум
С++ для начинающих
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
 
Рейтинг 4.50/6: Рейтинг темы: голосов - 6, средняя оценка - 4.50
0 / 0 / 1
Регистрация: 05.02.2014
Сообщений: 141
1

Вывести период дат. Курсовой проект.

12.04.2016, 17:09. Показов 1115. Ответов 20
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Моя программа читает из текстового файла информацию и в зависимости от выбора пользователя (это пункт 1) выводит котировки на экран. а выбрав пункт 2 пользователю будет предложено просмотреть котировки за выбранный период. и вот тут у меня засада. не выводит.

my.cpp
C++
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include "quotes.h"
#include <vector> // for vector
#include <fstream>//for use txt file,ifstream
#include <cstring> // for use strlen
 
void read_file (std::vector<const char*>&char_vector);
 
void read_file(std::vector<const char*>&char_vector){
    int local_count = 0;
    char str[100];
    char temp_date[11]=" ";
    std::ifstream fin("gold.txt");// open file
    if (!fin.is_open()){  // проверка наличие/возможность открыть файл
        std::cout<<"somthing wrong, chek file's name and restart the programm please\n";
    }else {
        while (fin){
            fin>>str;
            for (int i = 0; i < 10;++i){
              temp_date[i]=str[i];            
            }
            char_vector.push_back(temp_date);
            ++local_count;
            
        }
    }
    std::cout<<"we have period:"<<char_vector[0]<<" to "<<char_vector[local_count];
}
 
 
int main(){
    std::vector<const char*>char_vector(1);
    int choise;
    do{ 
        std::cout<<"what do you whant to do?:\n ";
        std::cout<<"1 - view all history\n";
        std::cout<<"2 - view date-period quotes\n";
        std::cin>>choise;
        fflush(stdin);
    
    } while (choise!=1 && choise!= 2);
    if (choise ==1){
        quotes obj1;
        obj1.show_quotes();
    } else if (choise == 2){
        read_file(char_vector);
    }
    std::cout<<"ok";
    //obj1.show_quotes();
    std::cin.get();
    return 0;
}
quotes.cpp
C++
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <iomanip> // for use setw
#include <vector> // for vector
#include <fstream>//for use txt file,ifstream
#include <cstring> //
#include <cstdlib> //for use atof
#include "quotes.h"
 
 
quotes::quotes():my_quotes(1){ //use this style for vector in cinstructor
    char str[100]=" ";
    count = 0;// use for count number vector
    std::ifstream fin("gold.txt");// open file
    if (!fin.is_open()){  // use it for open file
        std::cout<<"somthing wrong, chek file's name and restart the programm please\n";
    }else {
        while (fin){
            fin>>str;
            pars_file(my_quotes,count,str);
        }
    }
    fin.close(); // close file
}
 
void quotes::pars_file(std::vector<quotes_struct> &my_quotes,int&count,char* str){
    char temp_date[11] = " ";
    char temp_open[6]=" ";
    char temp_high[6] = " ";
    char temp_low[6] = " ";
    char temp_close[6] = " ";
    int k = 0;
    for (int i = 0; i < int(strlen(str)); ++i){//int for have no warning but warning only in linux in win it all ok- wtf?
        while (str[i]!=','){
            temp_date[k++] = str[i++];
        }
        k=0;
        ++i;
        while (str[i]!=','){
            ++i;//do nothing couse i need n't time data
        }
        ++i;
        k=0;
        while (str[i]!=','){
            temp_open[k++] = str[i++];
        }
        k=0;
        ++i;
        while (str[i]!=','){
            temp_close[k++] = str[i++];
        }
        k=0;
        ++i;
        while (str[i]!=','){
            temp_high[k++] = str[i++];
        }
        k = 0;
        ++i;
        while (str[i]!=','){
            temp_low[k++] = str[i++];
        }
        k=0;
        break;//i need n't volume data
    }
    
    strcpy(my_quotes[count].date,temp_date);//for copy char[]
    my_quotes[count].open = atof(temp_open);
    my_quotes[count].close = atof(temp_close);
    my_quotes[count].low = atof(temp_low);
    my_quotes[count].high = atof(temp_high);
    my_quotes.push_back(my_quotes_struct); // push it in vector and take some memmory
 
    ++count;
}
 
void quotes::show_quotes(){
    int i = 0;
    while (i<count){
        std::cout<<std::setw(6)<<my_quotes[i].date<<std::left<<" ";
        std::cout<<std::setw(6)<<my_quotes[i].open<<std::left<<" ";
        std::cout<<std::setw(6)<<my_quotes[i].close<<std::left<<" ";
        std::cout<<std::setw(6)<<my_quotes[i].high<<std::left<<" ";
        std::cout<<std::setw(6)<<my_quotes[i].low<<std::left<<"\n";
        ++i;
    }
 
}
quotec.h
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <vector>
 
class quotes {
    private:
    int count;
    struct quotes_struct{           //struct truly speaking always is public isn't it?
        double open,close,high,low;//open close max min
        char date[11];
    }my_quotes_struct;  
    
    std::vector<quotes_struct> my_quotes;
    
    public:
    quotes();//constructor always is public
    void pars_file(std::vector<quotes_struct> &my_quotes, int&, char*);
    void show_quotes();     
};
строка для компиляции g++ my.cpp quotes.cpp quotes.h -o main

ну программа еще не доделана, но вот затырка затырок. не выводит она мне период дат. че то я запутался совсем совсем
Миниатюры
Вывести период дат. Курсовой проект.  
Вложения
Тип файла: zip 1.zip (18.4 Кб, 2 просмотров)
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
12.04.2016, 17:09
Ответы с готовыми решениями:

Как вывести период дат
При запуске отчёта запрашивается фамилия препода, потом начальная дата, затем конечная дата,...

Как вывести в Dbgrid определенный период Дат
Как вывести в Dbgrid Определенный период Дат

Выборка дат за период
Доброго времени суток, подскажите пожалуйста, существует ли функция в оракл, которая возращает все...

Выбрать значения дат за период
Требуется написать запрос oracle. К примеру есть таблица в которой, есть объект его значение и...

20
7792 / 6559 / 2984
Регистрация: 14.04.2014
Сообщений: 28,671
12.04.2016, 19:45 2
Вот здесь заполняться должна my_quotes_struct, а добавляться в my_quotes.
C++
1
2
3
4
5
6
    strcpy(my_quotes[count].date,temp_date);//for copy char[]
    my_quotes[count].open = atof(temp_open);
    my_quotes[count].close = atof(temp_close);
    my_quotes[count].low = atof(temp_low);
    my_quotes[count].high = atof(temp_high);
    my_quotes.push_back(my_quotes_struct); // push it in vector and take some memmory
И если используешь STL, то для чего эти массивы char? Используй string + regex.
1
0 / 0 / 1
Регистрация: 05.02.2014
Сообщений: 141
13.04.2016, 09:30  [ТС] 3
nmcf, спасибо, сейчас буду смотреть

Добавлено через 12 часов 38 минут
nmcf, еще раз, спасибо, поправил
quotes.cpp
C++
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
#include <iomanip> // for use setw
#include <vector> // for vector
#include <fstream>//for use txt file,ifstream
#include <cstring> //
#include <cstdlib> //for use atof
#include "quotes.h"
 
 
quotes::quotes():my_quotes(1){ //use this style for vector in cinstructor
    char str[100]=" ";
    count = 0;// use for count number vector
    std::ifstream fin("gold.txt");// open file
    if (!fin.is_open()){  // use it for open file
        std::cout<<"somthing wrong, chek file's name and restart the programm please\n";
    }else {
        while (fin){
            fin>>str;
            pars_file(my_quotes,count,str);
        }
    }
    fin.close(); // close file
}
 
void quotes::pars_file(std::vector<quotes_struct> &my_quotes,int&count,char* str){
    char temp_date[11] = " ";
    char temp_open[6]=" ";
    char temp_high[6] = " ";
    char temp_low[6] = " ";
    char temp_close[6] = " ";
    int k = 0;
    for (int i = 0; i < int(strlen(str)); ++i){//int for have no warning
        while (str[i]!=','){
            temp_date[k++] = str[i++];
        }
        k=0;
        ++i;
        while (str[i]!=','){
            ++i;//do nothing couse i need n't time data
        }
        ++i;
        k=0;
        while (str[i]!=','){
            temp_open[k++] = str[i++];
        }
        k=0;
        ++i;
        while (str[i]!=','){
            temp_close[k++] = str[i++];
        }
        k=0;
        ++i;
        while (str[i]!=','){
            temp_high[k++] = str[i++];
        }
        k = 0;
        ++i;
        while (str[i]!=','){
            temp_low[k++] = str[i++];
        }
        k=0;
        break;//i need n't volume data
    }
    
    strcpy(my_quotes_struct.date,temp_date);//for copy char[]
    my_quotes_struct.open = atof(temp_open);
    my_quotes_struct.close = atof(temp_close);
    my_quotes_struct.low = atof(temp_low);
    my_quotes_struct.high = atof(temp_high);
    my_quotes.push_back(my_quotes_struct); // push it in vector and take some memmory
       ++count;
    
}
 
void quotes::show_quotes(){
    int i = 0;
    while (i<count){
        std::cout<<std::setw(6)<<my_quotes[i].date<<std::left<<" ";
        std::cout<<std::setw(6)<<my_quotes[i].open<<std::left<<" ";
        std::cout<<std::setw(6)<<my_quotes[i].close<<std::left<<" ";
        std::cout<<std::setw(6)<<my_quotes[i].high<<std::left<<" ";
        std::cout<<std::setw(6)<<my_quotes[i].low<<std::left<<"\n";
        ++i;
    }
 
}
regex я не знаю что это такое. (т.е. теперь то я знаю что это регулярные выражения, но что это и для чего я пока не знаю) с string та же петрушка. но сдается мне, что изначальная проблема лежит все такие не в области string и regex.
нет ли кого еще мыслей почему не выходит моя задумка (во всяком случае касаемо второго пункта программы)
0
7792 / 6559 / 2984
Регистрация: 14.04.2014
Сообщений: 28,671
13.04.2016, 09:50 4
regex сильно упростил бы анализ строки - то, что в pars_file().
Ты смешиваешь древние средства C с STL. Вот это: std::vector<const char*> для корректной работы потребует выделять и освобождать память вручную. У тебя read_file() возвращает в векторе указатели на локальный объект - это не корректно. Поэтому нужно использовать vector<string>, если есть потребность в такой структуре.
1
0 / 0 / 1
Регистрация: 05.02.2014
Сообщений: 141
13.04.2016, 12:03  [ТС] 5
nmcf, мммм спасибо ))) ой, я так радуюсь когда мне дают такие развернутые ответы, ну да я пока не до конца понял, что Вы мне сказали, но тут есть поле для размышлений ) спс

Добавлено через 2 часа 2 минуты
ну, я постарался, сделал что смог. изменил файл quotes.cpp компиляция прошла успешно, но при выполнение программы вышло сообщение "Ошибка сегментирования (сделан дамп памяти)" почуяв неладно я решил глянуть в gbd (это отладчик? да, я все правильно называю?) так он мне вообще выдал такое, что я покраснел.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff7b69853 in std::basic_ostream<char, std::char_traits<char> >& std::operator<< <char, std::char_traits<char>, std::allocator<char> >(std::basic_ostream<char, std::char_traits<char> >&, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) ()
from /usr/lib/x86_64-linux-gnu/libstdc++.so.6

поиск в yandex-google показал, что я пытаюсь обратиться (записать?) в ту область памяти которая мне для этого недоступна. я так понимаю что это связанно со строкой 22 файла my.cpp
char_vector.push_back(temp_date);
что приводит меня в замешательство, ведь push_back должен выделять память.
или же я должен воспользоваться советом данным (std::basic_string<char, std::char_traits<char>, std::allocator<char> > const& тут?

my.cpp
C++
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include <vector> // for vector
#include <fstream>//for use txt file,ifstream
//#include <string> // for use strlen
#include "quotes.h"
 
void read_file (std::vector<std::string>&char_vector);
 
void read_file(std::vector<std::string>&char_vector){
    int local_count = 0;
    std::string str;
    std::string temp_date;
    std::ifstream fin("gold.txt");// open file
    if (!fin.is_open()){  // проверка наличие/возможность открыть файл
        std::cout<<"somthing wrong, chek file's name and restart the programm please\n";
    }else {
        while (fin){
            fin>>str;
            for (int i = 0; i < 10;++i){
              temp_date+=str[i];//not sure it good idia for string            
            }
            char_vector.push_back(temp_date);
            ++local_count;
            temp_date.clear();//clear string temp_date
                        str.clear();//clear string str
            
        }
    }
    std::cout<<"we have period: "<<char_vector[0]<<" to "<<char_vector[local_count];//char_vector[0] - first element char_vector[local_count] - last element
}
 
 
int main(){
  std::vector<std::string>char_vector;//my first time at all i use  type string eee i try to lern stl
    int choise;
    do{ 
        std::cout<<"what do you whant to do?:\n ";
        std::cout<<"1 - view all history\n";
        std::cout<<"2 - view date-period quotes\n";
        std::cin>>choise;
        fflush(stdin);
    
    } while (choise!=1 && choise!= 2);
    if (choise ==1){
        quotes obj1;
        obj1.show_quotes();
    } else if (choise == 2){
        read_file(char_vector);
    }
    //std::cout<<"ok";
    //obj1.show_quotes();
    std::cin.get();
    std::cin.get();
    return 0;
}
угу, ну че, вот такой я программер, стыдно, да, но все равно прошу помощи.
0
7792 / 6559 / 2984
Регистрация: 14.04.2014
Сообщений: 28,671
13.04.2016, 12:43 6
Что делает вот это?
C++
1
2
3
4
5
6
7
8
9
10
11
        while (fin){
            fin>>str;
            for (int i = 0; i < 10;++i){
              temp_date+=str[i];//not sure it good idia for string            
            }
            char_vector.push_back(temp_date);
            ++local_count;
            temp_date.clear();//clear string temp_date
                        str.clear();//clear string str
            
        }
Что именно в файле? Почему цикл до 10?
1
0 / 0 / 1
Регистрация: 05.02.2014
Сообщений: 141
13.04.2016, 12:52  [ТС] 7
nmcf,
C++
1
2
3
4
5
6
7
8
9
10
11
        while (fin){ //пока не дошли до последней строки файла
            fin>>str; // помещаю каждую строчку в string str
            for (int i = 0; i < 10;++i){ // в строке меня интересуют только первые 9 символов тк именно они и составляют дату
              temp_date+=str[i];//not sure it good idia for string            
            }
            char_vector.push_back(temp_date); // кидаю temp_date в массив с выделением памяти
            ++local_count; // +1 локальному счетчику
            temp_date.clear();//clear string temp_date
                        str.clear();//clear string str
            
        }
я постарался описать то, что я делаю, эм, надеюсь так оно проясняет ход моих... ммм мыслей.
0
7792 / 6559 / 2984
Регистрация: 14.04.2014
Сообщений: 28,671
13.04.2016, 12:57 8
В строках нет пробельных символов? Тогда так:
C++
1
2
3
4
5
        while (fin>>str)
        {
            char_vector.push_back(str.substr(0, 9));
            ++local_count; // +1 локальному счетчику
        }
Для чего счётчик?
1
0 / 0 / 1
Регистрация: 05.02.2014
Сообщений: 141
13.04.2016, 13:44  [ТС] 9
nmcf, нет, там все идет подряд, в первом сообщение я приложил этот файл, так строки вот такого формата
2012.01.03,00:00,1572.3,1607.2,1571.5,1603.7,18647
local_count для строчки 29
C++
1
std::cout<<"we have period: "<<char_vector[0]<<" to "<<char_vector[local_count];//char_vector[0] - first element char_vector[local_count] - last element
хотя по local_count да это костыль, я посмотрю потом как в vector можно, эм уверен что можно брать иначе первый и последний элемент
0
7792 / 6559 / 2984
Регистрация: 14.04.2014
Сообщений: 28,671
13.04.2016, 13:48 10
substr(0, 10) - там 10 символов на дату.
0
0 / 0 / 1
Регистрация: 05.02.2014
Сообщений: 141
13.04.2016, 18:56  [ТС] 11
nmcf, спасибо, красивый вариант, но видимо string не так прост как char и у них (у стрингов) масса скелетов в шкафу))

C++
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <vector> // for vector
#include <fstream>//for use txt file,ifstream
//#include <string> // for use strlen
#include "quotes.h"
 
void read_file (std::vector<std::string>&char_vector);
 
void read_file(std::vector<std::string>&char_vector){
    int local_count = 0;
    std::string str;
    std::string temp_date;
    std::ifstream fin("gold.txt");// open file
    if (!fin.is_open()){  // проверка наличие/возможность открыть файл
        std::cout<<"somthing wrong, chek file's name and restart the programm please\n";
    }else {
        while (fin){
            fin>>str;
            char_vector.push_back(str.substr(0,10));
                        ++local_count;          
        }
    }
        std::string begin = char_vector.front();
        std::string end = char_vectcor.back();
        std::cout<<<"we have period: "<<begin<<" to "<<end;
 
}
 
int main(){
  std::vector<std::string>char_vector;//my first time at all i use  type string eee i try to lern stl
    int choise;
    do{ 
        std::cout<<"what do you whant to do?:\n ";
        std::cout<<"1 - view all history\n";
        std::cout<<"2 - view date-period quotes\n";
        std::cin>>choise;
        fflush(stdin);
    
    } while (choise!=1 && choise!= 2);
    if (choise ==1){
        quotes obj1;
        obj1.show_quotes();
    } else if (choise == 2){
        read_file(char_vector);
    }
    //std::cout<<"ok";
    //obj1.show_quotes();
    std::cin.get();
    std::cin.get();
    return 0;
}
вызывает сообщение об ошибке.... на 3! полных страницы ))) что пока выше моего понимания. Спасибо большое за помощь но на данном этапе я запутался еще больше, видимо мне надо время чтоб понять что же тут не так... хм, а может проще вернуться к char?
0
7792 / 6559 / 2984
Регистрация: 14.04.2014
Сообщений: 28,671
13.04.2016, 19:44 12
Не проще. Какая ошибка-то? Данные считываются? "we have period" верный?
Так сделай:
C++
1
2
3
4
5
        while (std::getline(fin, str))
        {
            char_vector.push_back(str.substr(0,10));
            ++local_count;          
        }
1
0 / 0 / 1
Регистрация: 05.02.2014
Сообщений: 141
13.04.2016, 21:12  [ТС] 13
nmcf, ошибка вот такая вот:
Bash
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
dima@dima-EasyNote-TE11HC:~/cpp/1$ g++ my.cpp quotes.cpp quotes.h -o main
my.cpp: In function ‘void read_file(std::vector<std::basic_string<char> >&)’:
my.cpp:24:26: error: ‘char_vectcor’ was not declared in this scope
         std::string end =char_vectcor.back();
                          ^
my.cpp:25:20: error: expected primary-expression before ‘<’ token
         std::cout<<<"we have period: "<<begin<<" to "<<end;
                    ^
my.cpp:25:39: error: no match for ‘operator<<(operand types are ‘const char [17]’ and ‘std::string {aka std::basic_string<char>})
         std::cout<<<"we have period: "<<begin<<" to "<<end;
                                       ^
my.cpp:25:39: note: candidates are:
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from my.cpp:1:
/usr/include/c++/4.8/ostream:548:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const unsigned char*)
     operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
     ^
/usr/include/c++/4.8/ostream:548:5: note:   template argument deduction/substitution failed:
my.cpp:25:41: note:   mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [17]’
         std::cout<<<"we have period: "<<begin<<" to "<<end;
                                         ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from my.cpp:1:
/usr/include/c++/4.8/ostream:543:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const signed char*)
     operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
     ^
/usr/include/c++/4.8/ostream:543:5: note:   template argument deduction/substitution failed:
my.cpp:25:41: note:   mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [17]’
         std::cout<<<"we have period: "<<begin<<" to "<<end;
                                         ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from my.cpp:1:
/usr/include/c++/4.8/ostream:530:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const char*)
     operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
     ^
/usr/include/c++/4.8/ostream:530:5: note:   template argument deduction/substitution failed:
my.cpp:25:41: note:   mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [17]’
         std::cout<<<"we have period: "<<begin<<" to "<<end;
                                         ^
In file included from /usr/include/c++/4.8/ostream:612:0,
                 from /usr/include/c++/4.8/iostream:39,
                 from my.cpp:1:
/usr/include/c++/4.8/bits/ostream.tcc:321:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const char*)
     operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
     ^
/usr/include/c++/4.8/bits/ostream.tcc:321:5: note:   template argument deduction/substitution failed:
my.cpp:25:41: note:   mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [17]’
         std::cout<<<"we have period: "<<begin<<" to "<<end;
                                         ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from my.cpp:1:
/usr/include/c++/4.8/ostream:513:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const _CharT*)
     operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
     ^
/usr/include/c++/4.8/ostream:513:5: note:   template argument deduction/substitution failed:
my.cpp:25:41: note:   mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [17]’
         std::cout<<<"we have period: "<<begin<<" to "<<end;
                                         ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from my.cpp:1:
/usr/include/c++/4.8/ostream:493:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, unsigned char)
     operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
     ^
/usr/include/c++/4.8/ostream:493:5: note:   template argument deduction/substitution failed:
my.cpp:25:41: note:   mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [17]’
         std::cout<<<"we have period: "<<begin<<" to "<<end;
                                         ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from my.cpp:1:
/usr/include/c++/4.8/ostream:488:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, signed char)
     operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
     ^
/usr/include/c++/4.8/ostream:488:5: note:   template argument deduction/substitution failed:
my.cpp:25:41: note:   mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [17]’
         std::cout<<<"we have period: "<<begin<<" to "<<end;
                                         ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from my.cpp:1:
/usr/include/c++/4.8/ostream:482:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, char)
     operator<<(basic_ostream<char, _Traits>& __out, char __c)
     ^
/usr/include/c++/4.8/ostream:482:5: note:   template argument deduction/substitution failed:
my.cpp:25:41: note:   mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [17]’
         std::cout<<<"we have period: "<<begin<<" to "<<end;
                                         ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from my.cpp:1:
/usr/include/c++/4.8/ostream:476:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, char)
     operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
     ^
/usr/include/c++/4.8/ostream:476:5: note:   template argument deduction/substitution failed:
my.cpp:25:41: note:   mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [17]’
         std::cout<<<"we have period: "<<begin<<" to "<<end;
                                         ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from my.cpp:1:
/usr/include/c++/4.8/ostream:471:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, _CharT)
     operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
     ^
/usr/include/c++/4.8/ostream:471:5: note:   template argument deduction/substitution failed:
my.cpp:25:41: note:   mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [17]’
         std::cout<<<"we have period: "<<begin<<" to "<<end;
                                         ^
In file included from /usr/include/c++/4.8/string:52:0,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from my.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:2753:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
     operator<<(basic_ostream<_CharT, _Traits>& __os,
     ^
/usr/include/c++/4.8/bits/basic_string.h:2753:5: note:   template argument deduction/substitution failed:
my.cpp:25:41: note:   mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [17]’
         std::cout<<<"we have period: "<<begin<<" to "<<end;
от такая вот красота ) такого у меня еще не было, вообще у меня много чего было, но такого не было ))
почему то мне кажется, что это особенность моего... эм. компилятора.
http://www.cplusplus.com/refer... tor/front/ беру элементы вектора по предоставленному примеру, но именно оно вызывает у меня подобные сообщения.
увы, но предлагаемый вариант вида
C++
1
2
3
4
5
6
while (std::getline(finstr)){
            fin>>str;
            char_vector.push_back(str.substr(0,10));
                        ++local_count;          
        }
    }
ситуацию не спасает ругается на 25 строчку
C++
1
std::cout<<<"we have period: "<<char_vector.front()<<" to "<<char_vector.back();
п.с. и спасибо больше, что Вы тратите свое время на меня. посылаю положительную энергию в космос )

Добавлено через 6 минут
хм, попробовал скомпилить вод виндой.. та же ошибка... епть, что же это такое

Добавлено через 10 минут
я невнимательное ламо ((( скомпилировал ))))) ща буду смотреть. ошибки в написании такие суровые ))))
0
0 / 0 / 1
Регистрация: 05.02.2014
Сообщений: 141
13.04.2016, 21:19  [ТС] 14
и все таки нет... ошибка
Bash
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
dima@dima-EasyNote-TE11HC:~/cpp/1$ g++ my.cpp quotes.cpp quotes.h -o main
my.cpp: In function ‘void read_file(std::vector<std::basic_string<char> >&)’:
my.cpp:25:12: error: expected primary-expression before ‘<’ token
 std::cout<<<"we have period: "<<char_vector.front()<<" to "<<char_vector.back();
            ^
my.cpp:25:31: error: no match for ‘operator<<(operand types are ‘const char [17]’ and ‘std::basic_string<char>)
 std::cout<<<"we have period: "<<char_vector.front()<<" to "<<char_vector.back();
                               ^
my.cpp:25:31: note: candidates are:
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from my.cpp:1:
/usr/include/c++/4.8/ostream:548:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const unsigned char*)
     operator<<(basic_ostream<char, _Traits>& __out, const unsigned char* __s)
     ^
/usr/include/c++/4.8/ostream:548:5: note:   template argument deduction/substitution failed:
my.cpp:25:51: note:   mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [17]’
 std::cout<<<"we have period: "<<char_vector.front()<<" to "<<char_vector.back();
                                                   ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from my.cpp:1:
/usr/include/c++/4.8/ostream:543:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const signed char*)
     operator<<(basic_ostream<char, _Traits>& __out, const signed char* __s)
     ^
/usr/include/c++/4.8/ostream:543:5: note:   template argument deduction/substitution failed:
my.cpp:25:51: note:   mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [17]’
 std::cout<<<"we have period: "<<char_vector.front()<<" to "<<char_vector.back();
                                                   ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from my.cpp:1:
/usr/include/c++/4.8/ostream:530:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, const char*)
     operator<<(basic_ostream<char, _Traits>& __out, const char* __s)
     ^
/usr/include/c++/4.8/ostream:530:5: note:   template argument deduction/substitution failed:
my.cpp:25:51: note:   mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [17]’
 std::cout<<<"we have period: "<<char_vector.front()<<" to "<<char_vector.back();
                                                   ^
In file included from /usr/include/c++/4.8/ostream:612:0,
                 from /usr/include/c++/4.8/iostream:39,
                 from my.cpp:1:
/usr/include/c++/4.8/bits/ostream.tcc:321:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const char*)
     operator<<(basic_ostream<_CharT, _Traits>& __out, const char* __s)
     ^
/usr/include/c++/4.8/bits/ostream.tcc:321:5: note:   template argument deduction/substitution failed:
my.cpp:25:51: note:   mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [17]’
 std::cout<<<"we have period: "<<char_vector.front()<<" to "<<char_vector.back();
                                                   ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from my.cpp:1:
/usr/include/c++/4.8/ostream:513:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const _CharT*)
     operator<<(basic_ostream<_CharT, _Traits>& __out, const _CharT* __s)
     ^
/usr/include/c++/4.8/ostream:513:5: note:   template argument deduction/substitution failed:
my.cpp:25:51: note:   mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [17]’
 std::cout<<<"we have period: "<<char_vector.front()<<" to "<<char_vector.back();
                                                   ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from my.cpp:1:
/usr/include/c++/4.8/ostream:493:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, unsigned char)
     operator<<(basic_ostream<char, _Traits>& __out, unsigned char __c)
     ^
/usr/include/c++/4.8/ostream:493:5: note:   template argument deduction/substitution failed:
my.cpp:25:51: note:   mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [17]’
 std::cout<<<"we have period: "<<char_vector.front()<<" to "<<char_vector.back();
                                                   ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from my.cpp:1:
/usr/include/c++/4.8/ostream:488:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, signed char)
     operator<<(basic_ostream<char, _Traits>& __out, signed char __c)
     ^
/usr/include/c++/4.8/ostream:488:5: note:   template argument deduction/substitution failed:
my.cpp:25:51: note:   mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [17]’
 std::cout<<<"we have period: "<<char_vector.front()<<" to "<<char_vector.back();
                                                   ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from my.cpp:1:
/usr/include/c++/4.8/ostream:482:5: note: template<class _Traits> std::basic_ostream<char, _Traits>& std::operator<<(std::basic_ostream<char, _Traits>&, char)
     operator<<(basic_ostream<char, _Traits>& __out, char __c)
     ^
/usr/include/c++/4.8/ostream:482:5: note:   template argument deduction/substitution failed:
my.cpp:25:51: note:   mismatched types ‘std::basic_ostream<char, _Traits>’ and ‘const char [17]’
 std::cout<<<"we have period: "<<char_vector.front()<<" to "<<char_vector.back();
                                                   ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from my.cpp:1:
/usr/include/c++/4.8/ostream:476:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, char)
     operator<<(basic_ostream<_CharT, _Traits>& __out, char __c)
     ^
/usr/include/c++/4.8/ostream:476:5: note:   template argument deduction/substitution failed:
my.cpp:25:51: note:   mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [17]’
 std::cout<<<"we have period: "<<char_vector.front()<<" to "<<char_vector.back();
                                                   ^
In file included from /usr/include/c++/4.8/iostream:39:0,
                 from my.cpp:1:
/usr/include/c++/4.8/ostream:471:5: note: template<class _CharT, class _Traits> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, _CharT)
     operator<<(basic_ostream<_CharT, _Traits>& __out, _CharT __c)
     ^
/usr/include/c++/4.8/ostream:471:5: note:   template argument deduction/substitution failed:
my.cpp:25:51: note:   mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [17]’
 std::cout<<<"we have period: "<<char_vector.front()<<" to "<<char_vector.back();
                                                   ^
In file included from /usr/include/c++/4.8/string:52:0,
                 from /usr/include/c++/4.8/bits/locale_classes.h:40,
                 from /usr/include/c++/4.8/bits/ios_base.h:41,
                 from /usr/include/c++/4.8/ios:42,
                 from /usr/include/c++/4.8/ostream:38,
                 from /usr/include/c++/4.8/iostream:39,
                 from my.cpp:1:
/usr/include/c++/4.8/bits/basic_string.h:2753:5: note: template<class _CharT, class _Traits, class _Alloc> std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&, const std::basic_string<_CharT, _Traits, _Alloc>&)
     operator<<(basic_ostream<_CharT, _Traits>& __os,
     ^
/usr/include/c++/4.8/bits/basic_string.h:2753:5: note:   template argument deduction/substitution failed:
my.cpp:25:51: note:   mismatched types ‘std::basic_ostream<_CharT, _Traits>’ and ‘const char [17]’
 std::cout<<<"we have period: "<<char_vector.front()<<" to "<<char_vector.back();
при версии файла my.cpp
C++
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <iostream>
#include <vector> // for vector
#include <fstream>//for use txt file,ifstream
//#include <string> // for use strlen
#include "quotes.h"
 
void read_file (std::vector<std::string>&char_vector);
 
void read_file(std::vector<std::string>&char_vector){
    int local_count = 0;
    std::string str;
    std::string temp_date;
    std::ifstream fin("gold.txt");// open file
    if (!fin.is_open()){  // проверка наличие/возможность открыть файл
        std::cout<<"somthing wrong, chek file's name and restart the programm please\n";
    }else {
while (std::getline(fin,str)){
            fin>>str;
            char_vector.push_back(str.substr(0,10));
                        ++local_count;          
        }
    }
//std::string begin = char_vector.front();
//    std::string end =char_vector.back();
std::cout<<<"we have period: "<<char_vector.front()<<" to "<<char_vector.back();
 
}
 
int main(){
  std::vector<std::string>char_vector;//my first time at all i use  type string eee i try to lern stl
    int choise;
    do{ 
        std::cout<<"what do you whant to do?:\n ";
        std::cout<<"1 - view all history\n";
        std::cout<<"2 - view date-period quotes\n";
        std::cin>>choise;
        fflush(stdin);
    
    } while (choise!=1 && choise!= 2);
    if (choise ==1){
        quotes obj1;
        obj1.show_quotes();
    } else if (choise == 2){
        read_file(char_vector);
    }
    //std::cout<<"ok";
    //obj1.show_quotes();
    std::cin.get();
    std::cin.get();
    return 0;
}
прикладываю архив всех файлов. в принципе курсовик соооовсем не горит, но, конечно разобраться бы где ж я косячу то
Вложения
Тип файла: zip 1.zip (18.4 Кб, 1 просмотров)
0
7792 / 6559 / 2984
Регистрация: 14.04.2014
Сообщений: 28,671
13.04.2016, 21:24 15
Опечатки у тебя: 'char_vectcor', тройное <<<.
Внимательно читай текст ошибок.
1
0 / 0 / 1
Регистрация: 05.02.2014
Сообщений: 141
13.04.2016, 21:36  [ТС] 16
сгораю со стыда. спасибо Вам ))))

Добавлено через 4 минуты
но почему то выдает we have period: 2012.01.04 to
char_vector.back(); видимо где то ошибка. только не подсказывайте ))) я завтра буду дальше ковырять.

да, < я пропустил. конец дня и тд ))) и вообще раньше у меня было все удобно. win 7 notepad++. но мне сказали, что это не тру и у меня должен быть linux и macs и это тру... правда после этого мой уровень кунг-фу с нулевого вообще ушел в область отрицательных значений...
0
7792 / 6559 / 2984
Регистрация: 14.04.2014
Сообщений: 28,671
13.04.2016, 21:52 17
Тру - это писать на коленке?
Установи Qt c QtCreator и пользуйся.
1
0 / 0 / 1
Регистрация: 05.02.2014
Сообщений: 141
14.04.2016, 09:26  [ТС] 18
nmcf, мужчина, спасибо Вам, теперь у меня работает так как я и планировал, вас очень благодарю, что потратили на меня столько Вашего времени, проект свой я конечно еще не доделал, но теперь мне надо посидеть над ним полюбоваться, порадоваться за свои успехи, погрустить, что они не такие уж и мои и подумать, что же мне там надо делать дальше, ну а заодно посмотреть, что ее мне удобней будет emacs ellipse Qt или же просто gedit.

we have period: 2012.01.03 to 2016.04.05
it's so cool )
0
0 / 0 / 1
Регистрация: 05.02.2014
Сообщений: 141
15.04.2016, 10:44  [ТС] 19
nmcf, можно вопрос? когда вы говорили про regex что имелось в виду? это класс stl или boost?
0
7792 / 6559 / 2984
Регистрация: 14.04.2014
Сообщений: 28,671
15.04.2016, 14:00 20
std::regex для разделения на составляющие строк типа этой: "2012.01.03,00:00,1572.3,1607.2,1571.5,1603.7,18647".
1
15.04.2016, 14:00
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
15.04.2016, 14:00
Помогаю со студенческими работами здесь

Разбить период дат на заданные периоды
Добрый день всем! Задан период дат типа 01.01.2020 - 31.05.2020 Необходимо разбить его на...

Определить все понедельники за период дат
Есть период дат, нужно получить даты всех понедельников входящих в этот период. В теории цикл от...

phpmyadmin SQL, выборка дат за период
Как мне выбрать из БД только записи за последний день, неделю, месяц?...

Как из разницы дат убрать ненужный период?
Форумчане, добрый день! Помогите решить проблему... Имеется, пример: 1.Период от 01.01.2016...

Модуль с определением двух дат, определяющих период времени (в формате «чч.мм.гггг»)
Помогите ,пожайлуста, найти в модуле с определением двух дат, определяющих период времени (в...

Удаление из папки всех файлов и папок созданных/измененных за конкретный год или период дат
на форме 2 текстовых поля, в которые пользователь вводит период дат, текстовое поле с выбором...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
20
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru