Если вы хотите ограничить использование активности вашим собственным приложением, вы должны добавить exported=false
в оператор манифеста вашего действия.
Если вы хотите разрешить другим приложениям использовать его (явно через его имя класса или, лучше, с использованием намерения с типом данных или действием), то у вас есть два варианта:
-
То же рассуждение относится к службе, с tools:ignore="ExportedService"
и контентом провайдеров с tools:ignore="ExportedContentProvider"
.
Для начала не используйте std::cin
для тестирования. Просто установите значение в вашем коде для согласованности и простоты разработки. Используйте эту страницу для справки.
#include <iostream>
#include <string>
int main() {
std::string str("this and_that are the tests");
auto start = str.find_first_of(" ,\n", 0);
auto end = str.find_first_of(" ,\n", start + 1);
std::cout << str.substr(start, end - start);
return 0;
}
И это все еще что-то вроде хака, это просто зависит от того, куда ты идешь. Например, библиотека Boost богата расширенными манипуляциями со строками. Если вы собираетесь разобрать более одного слова, это все равно можно сделать с помощью манипуляций со строками, но специальные парсеры могут выйти из-под контроля. Есть и другие инструменты, такие как Boost Spirit , чтобы держать код под контролем.
#include"iostream"
#include<stdio.h>
#include<string>
#include <ctype.h>
using namespace std;
int main()
{
char c;
string str;
char emp = ' ';
cout<<"Enter a string: ";
getline (cin,str);
int j = 0, count = 1, counter = 0;
for (int i = 0; i < str.length() && count != 2; i++)
{
cout<< str[i] <<endl;
if( isspace(str[i]) || str[i] == ',' || str[i] == '\t' )
{
count++;
if(count == 2)
{
j = i+1;
while(j < str.length())
{
if (isspace(str[j]) || str[j] == ',' || str[j] == '\t')
{
break;
}
cout<<str[j];
counter++;
j++;
}
cout<<endl;
}
}
}
cout<<"size of the word: "<<counter<<endl;
return 0;
}
Это простой ответ на то, что вы хотите, надеюсь помочь вам.
Разделители, используемые при извлечении из потока, зависят от действующего в настоящее время locale
. Один (громоздкий) способ изменить поведение при извлечении - создать новую локаль со специальным facet
, в котором вы указываете свои собственные разделители. В приведенном ниже примере новая локаль используется для непосредственного добавления std::stringstream
вместо std::cin
. Часть создания фасета - это в основном копирование / вставка из других ответов здесь, на SO, поэтому вы найдете множество других примеров.
#include <iostream>
#include <locale> // std::locale, std::ctype<char>
// https://en.cppreference.com/w/cpp/locale/ctype_char
#include <sstream> // std::stringstream
#include <algorithm> // std::copy_n
#include <vector> // a container to store stuff in
// facet to create our own delimiters
class my_facet : public std::ctype<char> {
mask my_table[table_size];
public:
my_facet(size_t refs = 0)
: std::ctype<char>(&my_table[0], false, refs)
{
// copy the "C" locales table to my_table
std::copy_n(classic_table(), table_size, my_table);
// and create our delimiter specification
my_table[' '] = (mask)space;
my_table['\t'] = (mask)space;
my_table[','] = (mask)space;
}
};
int main() {
std::stringstream ss;
// create a locale with our special facet
std::locale loc(std::locale(), new my_facet);
// imbue the new locale on the stringstream
ss.imbue(loc);
while(true) {
std::string line;
std::cout << "Enter sentence: ";
if(std::getline(std::cin, line)) {
ss.clear(); // clear the string stream from prior errors etc.
ss.str(line); // assign the line to the string stream
std::vector<std::string> words; // std::string container to store all words in
std::string word; // for extracting one word
while(ss>>word) { // extract one word at a time using the special facet
std::cout << " \"" << word << "\" is " << word.size() << " chars\n";
// put the word in our container
words.emplace_back(std::move(word));
}
if(words.size()>=2) {
std::cout << "The second word, \"" << words[1] << "\", is " << words[1].size() << " chars\n";
} else {
std::cout << "did not get 2 words or more...\n";
}
} else break;
}
}