Ошибка компилятора на версии Visual studio 2010
При запуске компилятора высвечивается ошибки "string subscript out of range". Версия Visual studio 2010.
В 19 версии все работает хорошо.
Что выдает компилятор: 'laba.exe': Loaded 'C:\Users\Danila\Documents\Visual Studio 2010\Projects\laba\Debug\laba.exe', Symbols loaded. 'laba.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\apphelp.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\msvcp100d.dll', Symbols loaded. 'laba.exe': Loaded 'C:\Windows\SysWOW64\msvcr100d.dll', Symbols loaded. 'laba.exe': Loaded 'C:\Windows\SysWOW64\sechost.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\rpcrt4.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\sspicli.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\cryptbase.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\bcryptprimitives.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\user32.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\win32u.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\gdi32.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\gdi32full.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\msvcp_win.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\ucrtbase.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\imm32.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\uxtheme.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\msvcrt.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\combase.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\msctf.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\oleaut32.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\advapi32.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\dwmapi.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\crypt32.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\msasn1.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\cryptsp.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\kernel.appcore.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\TextInputFramework.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\CoreMessaging.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\CoreUIComponents.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\SHCore.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\WinTypes.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\ntmarta.dll', Cannot find or open the PDB file 'laba.exe': Loaded 'C:\Windows\SysWOW64\ole32.dll', Cannot find or open the PDB file The thread 'Win32 Thread' (0x1b78) has exited with code 3 (0x3). The thread 'Win32 Thread' (0x2a64) has exited with code 3 (0x3). The thread 'Win32 Thread' (0x2178) has exited with code 3 (0x3). The program '[7740] laba.exe: Native' has exited with code 3 (0x3).
(КОД)
#include <iostream>
#include <string>
#include <fstream>
#include <clocale>
#include <windows.h>
#include <conio.h>
using namespace std;
void Print_f(const char Name[]) //Вывод файла на экран
{
ifstream file(Name, ios::in);
string limebuff;
while (getline(file, limebuff))
cout << limebuff << endl;
file.close();
cin.get();
}
int space(string a) // считает количество пробелов в строке
{
int i = 0, k = 0;;
while (a[i] != '\0') // '\0' - конец строки
{
if (a[i] == ' ')
k++;
i++;
}
return k;
}
void more_space_then_need(string& a, int i) //если пробелов между 2 словами больше одного, удаляет лишние
{
while ((a[i] == ' ') && (i > 0 && a[i - 1] == ' ' || (i < a.length() - 1) && a[i + 1] == ' '))
a.erase(i, 1);
}
void space_before_pm(string& a, int i) // удаляет пробел после знака препинания
{
if (a[i] == ' ' && (a[i + 1] == '.' || a[i + 1] == ',' || a[i + 1] == '!' || a[i + 1] == '?' || a[i + 1] == ':' || a[i + 1] == ';'))
a.erase(i, 1);
}
void first_space(string& a) //удаляет лишний пробел перед 1 словом
{
while (a[0] == ' ')
a.erase(0, 1);
}
void last_space(string& a) //удаляет лишний пробел после последнего слова
{
while (a[a.length() - 1] == ' ')
a.erase(a.length() - 1, 1);
}
void lost_space_after_pm(string& a, int i) // если нет пробела после знака препинания, добавляет его
{
if (i < a.length() && (a[i] == '.' || a[i] == ',' || a[i] == '!' || a[i] == '?' || a[i] == ':' || a[i] == ';') && (a[i + 1] != ' '))
a.insert(i + 1, " ");
}
void check_on_error(string& a) // все функции , связанные с пробелами, запускаются тут
{
int i = 0;
while (i < a.length())
{
more_space_then_need(a, i);
first_space(a);
last_space(a);
space_before_pm(a, i);
lost_space_after_pm(a, i);
i++;
}
}
void rebuild_strings(const char name_in[], const char name_out[]) //проверяется файл на наличие ошибок в пробелах
{
ifstream in(name_in);
if (!in.is_open())
{
cout << endl << "Отсутствует файл Input.txt ! Программа завершена." << endl;
}
else
{
ofstream out(name_out);
string s;
while (getline(in, s))
{
check_on_error(s);
out << s << endl;
}
}
}
string word(string a, int& i) //из строки берется слово
{
string b;
for (i; (i < a.length()) && (a[i] != ' ' && a[i] != '.' && a[i] != ',' && a[i] != ';' && a[i] != ':' && a[i] != '!' && a[i] != '?'); i++)
b += a[i];
return b;
}
void find_word_in_string(const char name[], string a) // поиск слова в словах ( задание 5)
{
ifstream in(name);
string words;
int schet = 1;
while (getline(in, words))
{
string answer;
for (int i = 0; i < words.length(); i++)
{
string sl = word(words, i);
for (int g = 0; sl[g] != '\0'; g++)
{
if (sl[g] == a[0])
{
bool f = true;
int h = 0;
for (int j = 0, d = g; a[j] != '\0' && sl[d] != '\0'; j++, d++)
{
if (a[j] != sl[d])
f = false;
h++;
}
if (f && (h == a.length()))
{
answer += sl;
answer += " ";
}
/*else
{
answer += " ";
}*/
}
}
}
cout << schet << " строка: ";
if (answer.length() == 0)
{
cout << "в этой строке слово не найдено" << endl;
}
else
{
cout << answer << endl;
}
schet++;
}
}
void Variant(const char name_in[], const char name_out[]) //Вариант
{
ifstream in(name_in);
if (!in.is_open())
{
cout << endl << "Отсутствует файл Output.txt ! Программа завершена." << endl;
}
else
{
ofstream out(name_out);
string words;
int kolvo = 0;
while (getline(in, words) && kolvo < 10)
{
while (words.length() > 60)
words.erase(words.length() - 1, 1);
string answer;
for (int i = 0; i < words.length(); i++)
{
string sl = word(words, i);
bool f = false;
char sa = sl[sl.length() - 1];
if (sa == 'а' || sa == 'е' || sa == 'ё' || sa == 'и' || sa == 'о' ||
sa == 'у' || sa == 'ы' || sa == 'э' || sa == 'ю' || sa == 'я' ||
sa == 'А' || sa == 'Е' || sa == 'Ё' || sa == 'И' || sa == 'О' ||
sa == 'У' || sa == 'Ы' || sa == 'Э' || sa == 'Ю' || sa == 'Я')
{
f = true;
}
if (f)
{
answer += sl;
answer += " ";
}
}
kolvo++;
out << answer << endl;
}
}
}
int main(int argc, char** argv)
{
system("chcp 1251 > null");
setlocale(LC_ALL, "ru");
string start;
char key;
do {
cout << endl;
cout << "Введите строку: ";
getline(cin, start);
cout << "Символов в строке: " << start.length() << endl << "Пробелов в строке: " << space(start) << endl;
check_on_error(start);
cout << endl << "\tПроверка измененой строки" << endl << endl << "Символов в строке: " << start.length() << endl << "Пробелов в строке: " << space(start) << endl << endl << "Вывод строки: " << start << endl;
rebuild_strings("input.txt", "output.txt");
cout << endl << "Какое слово вы хотите найти в файле? : ";
string slovo;
getline(cin, slovo);
find_word_in_string("output.txt", slovo);
Variant("output.txt", "new.txt");
cout << endl << "Вывод созданного файла на экран(Вариант): " << endl;
cout << "--------------------------------" << endl;
Print_f("new.txt");
cout << "--------------------------------" << endl;
//system("notepad.exe new.txt");
printf(" >> Ещё разок? [Да - любой знак/ Нет - N]: ");
key = _getch();
} while (key != 'n' && key != 'N');
printf("\n >> Нажмите что-нибудь для выхода... ");
_getch();
system("pause");
return 0;
}