using namespace std; void ProbelVoid(char *str) { char *str1=new char [512]; int i = 0; for (char* a = str, *b = str1; *a; ++a, ++b, i++) { for (; *a == ' ' && *(a + 1) == ' '; a++); *b = *a; } str1[i] = '\0'; strcpy_s(str, strlen(str1), str1); } int main() { ifstream in("1.txt"); if (!in) { cout << "Ошибка: не могу открыть входной файл "; system("pause"); return-1; } char *str=new char[512]; in.getline(str, 512); cout << "Изначальная строка\n" << str; ProbelVoid(str); cout << "\n\nИзменённая строка\n" << str; ofstream out("output.txt"); out << str; cout << endl; out.close(); in.close(); system("pause"); return 0; } I can not alter under a dynamic array, so that from the file without problems you can use any size of text in the program (removes extra spaces)
std::string? (that memory needs to be freed, I am already silent) - KoVadimstd::stringusingstd::getline. All machine will be highlighted. - KoVadim