IPB
ЛогинПароль:

> Внимание!

1. Пользуйтесь тегами кода. - [code] ... [/code]
2. Точно указывайте язык, название и версию компилятора (интерпретатора).
3. Название темы должно быть информативным.
В описании темы указываем язык!!!

Наладить общение поможет, если вы подпишитесь по почте на новые темы в этом форуме.

> Строки класса String, Visual C++
сообщение
Сообщение #1


Новичок
*

Группа: Пользователи
Сообщений: 13
Пол: Мужской
Реальное имя: Вася

Репутация: -  0  +


Здравствуйте помогите пожалуйста с задачами:
1) Написать программу, которая считывает текст из файла и выводит на экран только вопросительные предложения из этого текста.
#include "stdafx.h"
#include <fstream>
#include <sstream>
#include <string>
#include <iostream>
using namespace std;
bool isLimit(char c)
{
char lim[]={' ','\t','\n'};
for (int i=0;i<sizeof(lim);++i)
if(c==lim[i])return true;return false;}

int _tmain(int argc, _TCHAR* argv[])
{
ifstream fin("infile.txt",ios::in|ios::nocreate);
if (!fin)
{
cout<<"oshibka otkritiy faila";
return 1;
}
int count=0; string word;
ostringstream sentence;
while(!fin.eof()){
char symb;
while(isLimit(symb=fin.peek()))
{
sentence<<symb;
if(symb=='\n')break;
fin.seekg(1,ios::cur);
}
fin>>word;
sentence<<word;
char last=word[word.size()-1];
if((last=='.')||(last=='!'))
{
sentence.str("");
continue;
}
if(last=='?')
{
cout<<sentence.str();
sentence.str("");
count++;
}
}
if(!count)cout<<"Voprositelnix predlozenii net";
return 0;
}


Две ошибки при компиляции: error C2039: '_Nocreate' : is not a member of 'basic_ios<char,struct std::char_traits<char> >' и error C2065: '_Nocreate' : undeclared identifier
2) Написать программу, формирующую из заданного текстового файла словарь, т.е. текстовый файл, содержащий все слова исходного файла
#include <fstream.h>
#include <iostream.h>
#include <string.h>
#include <stdlib.h>

int main(){
int const length=31;
struct Word{
char word[length];
};
char curword[length];

ifstream fin("example.txt", ios::in|ios::nocreate);
if(!fin){cout<<"ERROR"<<endl; return 1;}

int l=10000;
char *zuf=new char[l];
ofstream out("out.txt",ios::out|ios::nocreate);
if(!out){cout<<"ERROR"<<endl; return 2;}

int const more=1000000;
Word w2[more];
int i=0;
while(!fin.eof()){
if (i>more){cout<<"It is too long file!!! "<<endl;return 3;}
fin>>curword;
i++;
}

for(int g=0;g<i;g++)
for(int k=g;k<i;k++){
if(strcmp(w2[g].word, w2[k].word) > 0){
Word buf=w2[k];
w2[k]=w2[g];
w2[g]=buf;
}
}
int n=0;
while (n<i){
out<<w2[n].word;
n++;
}



return 0;
}


Эта компилируется но не работает
 Оффлайн  Профиль  PM 
 К началу страницы 
+ Ответить 
 
 Ответить  Открыть новую тему 
Ответов
сообщение
Сообщение #2


Гость






Цитата
а в коде это как
А в коде это вот так:

#include <string>
#include <vector>
#include <iostream>
#include <iterator>
#include <fstream>

using namespace std;

void split_string(const std::string& str, vector<string>& v,
const std::string& delim = ",")
{
std::string::size_type lpos = 0;
std::string::size_type pos = str.find_first_of(delim, lpos);
do
{
string s = str.substr(lpos, pos - lpos);
if(!s.empty()) {
v.push_back(s);
}
lpos = ( pos == std::string::npos ) ? std::string::npos : pos + 1;
pos = str.find_first_of(delim, lpos);
}
while(lpos != std::string::npos);
}

int main() {
ifstream fin("infile.txt", ios::in);

ofstream fout("outfile.txt", ios::out);
ostream_iterator<string> out_it(fout, "\n" );

string s;
vector<string> buffer;

while(!fin.eof()) {
getline(fin, s); // читаем очередную строку из файла
split_string(s, buffer, ".,:?! "); // разбиваем ее на слова и заносим их в buffer
}
fin.close();

sort(buffer.begin(), buffer.end()); // сортируем слова по алфавиту

// копируем в выходной файл с удалением дубликатов
unique_copy(buffer.begin(), buffer.end(), out_it);
fout.close();

return 0;
}

yes2.gif
 К началу страницы 
+ Ответить 

Сообщений в этой теме


 Ответить  Открыть новую тему 
1 чел. читают эту тему (гостей: 1, скрытых пользователей: 0)
Пользователей: 0

 





- Текстовая версия 29.03.2024 18:30
500Gb HDD, 6Gb RAM, 2 Cores, 7 EUR в месяц — такие хостинги правда бывают
Связь с администрацией: bu_gen в домене octagram.name