tell cin to stop reading at newline

You can read all whitespace by setting noskipws on the istream:

#include <ios>
#include <iostream>
#include <vector>

using std::vector;

vector<int> getc() {
    char c;
    vector<int> cl;
    std::cin >> std::noskipws;
    while (std::cin >> c && c != '\n') {
        cl.push_back(c);
        std::cin >> c;
    }
    return cl;
}

If the standard input contains only a single line, you might as well construct the vector with the istream_iterator:

#include <iostream>
#include <iterator>
#include <vector>

using std::vector;

vector<int> getc() {
    // Replace char with int if you want to parse numbers instead of character codes
    vector<int> cl{
        std::istream_iterator<char>(std::cin),
        std::istream_iterator<char>()
    };
    return cl;
}

You can use the getline method to first get the line, then use istringstream to get formatted input from the line.


Use getline and istringstream:

#include <sstream>
/*....*/
vector<int> getclause() {
  char c;
  vector<int> cl;
  std::string line;
  std::getline(cin, line);
  std::istringstream iss(line);
  while ( iss >> c) {    
    cl.push_back(c);
  }
  return cl;
}

Tags:

C++