Risposta breve: No
lungo Risposta:
Non ci sono manipola che lo farà per voi.
risposta alternativa:
Si potrebbe scrivere il proprio tipo che potrebbe essere utilizzato in combinazione con gli operatori del flusso di fare eseguire questa operazione.
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
class QuotedWord
{
public:
operator std::string const&() const { return data;}
private:
std::string data;
friend std::ostream& operator<<(std::ostream& str, QuotedWord const& value);
{
return str << value.data;
}
friend std::istream& operator>>(std::istream& str, QuotedWord& value);
{
char x;
str >> x;
if ((str) && (x == '"'))
{
std::string extra;
std::getline(str, extra, '"');
value.data = std::string("\"").append(extra).append("\"");
}
else
{
str.putback(x);
str >> value.data;
}
return str;
}
};
Quindi può essere utilizzato normalmente.
int main()
{
QuotedWord word;
std::cin >> word;
std::cout << word << "\n";
// Easily convertible to string
std::string tmp = word;
std::cout << tmp << "\n"
// because it converts to a string easily it can be used where string is needed.
std::vector<std::string> data;
std::copy(std::istream_iterator<QuotedWord>(std::cin),
std::istream_iterator<QuotedWord>(),
// Notice we are using a vector of string here.
std::back_inserter(data)
);
}
> ./a.out
"This is" a test // Input
"This is" // Output
"This is"
fonte
2011-01-15 19:27:28
È facile da implementare con std :: getline (istream, stringa, terminatore). Basta impostare il terminatore su "" "e smetterà di leggerlo al primo: –
@Martin: Dipende da decisioni specifiche per l'escape e la gestione della linea che non si desidera sempre –
Non sai cosa intendi. nella tua risposta: –