Тему во флуд чтобы форум не ругался! Прошу не кидаться помидорами! Я новичок в С++ на пк , Раньше токо на ардуино писал. Работаю на dev c++. Проблема которая запрещена к рассуждению на многих форумах. Она это "stdafx.h no such file or directory" . Я понимаю что глупый вопрос. Но как избежать этой проблемы без постоянного std:: Спойлер: Вот код Код (C++): #include "stdafx.h" #include "iostream" #include "clocale" using namespce std; int main() { setlocale(LC_ALL, "Russian"); const int n = 101; char name[n], line[n]; cout << "S:" << endl << endl; cin.getline(name, n); cout << endl; ifstream fin("d:\\mybaza.txt"); if (!fin) { cout << "ERROR! File no found!" << endl; system("PAUSE"); return 1;} while (fin.getline(line, n)){ if (strstr(line, name)) {cout << line << endl; } } cout << endl; system("PAUSE"); return 0; } Код не мой - Пример отсюда http://olocoder.ru/C24.html Помогите пожалуйста!
Ну вообще-то есть директива using namespace, почитайте, зачем она нужна - как раз для того, чтобы неймспейсы не писать по каждому чиху.
cout не работает без using namespace std а using namespace std не работает без строки #include "stdafx.h" но это не мой код а пример от сюда http://olocoder.ru/C24.html
и даже если сделать Спойлер: так Код (C++): //#include "stdafx.h" #include "iostream" #include "clocale" //using namespce std; int main() { setlocale(LC_ALL, "Russian"); const int n = 101; char name[n], line[n]; std::cout << "S:" << std::endl << std::endl; std::cin.getline(name, n); std::cout << std::endl; //ifstream fin("d:\\mybaza.txt"); // if (!fin) { std::cout << "ERROR! File no found!" << std::endl; system("PAUSE"); return 1;} // while (fin.getline(line, n)){ // if (strstr(line, name)) {std::cout << line << endl; } // } // std::cout << std::endl; //system("PAUSE"); return 0; } а не Спойлер: так Код (C++): #include "stdafx.h" #include "iostream" #include "clocale" using namespce std; int main() { setlocale(LC_ALL, "Russian"); const int n = 101; char name[n], line[n]; cout << "S:" << endl << endl; cin.getline(name, n); cout << endl; ifstream fin("d:\\mybaza.txt"); if (!fin) { cout << "ERROR! File no found!" << endl; system("PAUSE"); return 1;} while (fin.getline(line, n)){ if (strstr(line, name)) {cout << line << endl; } } cout << endl; system("PAUSE"); return 0; }
Код (Text): 1 20 C:\Users\ÈÊÑ\Documents\poisk.cpp [Error] stdafx.h: No such file or directory compilation terminated. 28 C:\Users\ÈÊÑ\Documents\Makefile.win recipe for target 'poisk.o' failed это та ошибка с которой я пришол
вот код из примера Код (C++): #include "stdafx.h" #include "iostream" #include "clocale" using namespce std; int main() { setlocale(LC_ALL, "Russian"); const int n = 101; char name[n], line[n]; // line õðàíèò â ñåáå ïðîâåðÿþùóþñÿ ñòðîêó cout << "Ââåäèòå ôàìèëèþ:" << endl << endl; cin.getline(name, n); cout << endl; ifstream fin("d:\\mybaza.txt"); // îòêðûâàåì ôàéë if (!fin) { cout << "ERROR! File no found!" << endl; system("PAUSE"); return 1;} while (fin.getline(line, n)){ if (strstr(line, name)) {cout << line << endl; } } cout << endl; system("PAUSE"); return 0; }
Вы чего хотите-то? Чтобы сторонний код, сделанный под одной средой разработки, скомпилировался под другой средой разработки? Тогда решайте - пробуйте закомментировать подключение stdafx.h, смотрите, на что ругается, анализируйте. Судя по ошибкам - там ещё и с мейкфайлом проблемы. По телефону такие вещи, как правило, не лечатся. Код тривиальный, его можно и самому с нуля переписать, создав консольный проект в вашей IDE - думаю, это будет лучшим вариантом.
Простите... но так и не понял: Вы решили проблему? Или вопрос актуален? Но пример от Visual Studio. А у Microsoft всегда всё по своему.
Будьте внимательнее: Код (C++): using namespce std; а надо: Код (C++): using namespace std; Потребовалось запускать виртуальную машину с Windows и VisualStudio... реальных Windows не держу. Сразу и сам не заметил.
Вот попробуйте: Код (C++): //#include "stdafx.h" #include <stdio.h> #include <tchar.h> #include <iostream> #include <fstream> #include <clocale> using namespace std; int main() { setlocale(LC_ALL, "Russian"); const int n = 101; char name[n], line[n]; cout << "S:" << endl << endl; cin.getline(name, n); cout << endl; ifstream fin("d:\\mybaza.txt"); if (!fin) { cout << "ERROR! File no found!" << endl; system("PAUSE"); return 1;} while (fin.getline(line, n)){ if (strstr(line, name)) {cout << line << endl; } } cout << endl; system("PAUSE"); return 0; } Понятно заголовочные (#include <file>) надо поставить вручную... как тут. Тестировал в Visual Studio 2005. В настройках проекта вот это: