#Input with spaces

11 messages · Page 1 of 1 (latest)

toxic hound
#

Hi my code works perfectly for all strings except when there are spaces. Could someone help me figure out the bug here ?

tardy mothBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

toxic hound
#
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define INF 1000000000
#define MOD 1000000007

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("input", "r", stdin);
    //freopen("output", "w", stdout);
    int n = 1, t = 1;
    int x = 0;
    string f;
    while ((cin >> n >> t) && (n && t > 0)) {
        x++;
        for (int i = 0; i < n; i++) {
            cin.ignore();
            getline(cin, f);
        }
        vector <pair<double, pair<int, string>>> v;
        for (int i = 0; i < t; i++) {
            getline(cin, f);
            double j;int h; cin >> j >> h;
            v.pb({ h,{j,f} });
            for (int m = 0; m < h;m++) {
                getline(cin, f);
            }
        }
        sort(v.begin(), v.end());
        if (n > 0)
            cout << "RFP #" << x << "\n" << v[t - 1].se.se << endl;

    }
    return 0;
}```
light raven
#

time to step trough your code to see why it's not working as expected

dire pagoda
#

console input separates when theres a space

#

;compile c++ | hello world


int main() {
    std::string str;
    std::cin >> str;
    std::cout << str;
}```
subtle marlinBOT
#
Program Output
hello
dire pagoda
#

vs this

#

;compile cpp | hello world


int main() {
    std::string str;
    std::getline(std::cin, str);
    std::cout << str;

}```
subtle marlinBOT
#
Program Output
hello world
tardy mothBOT
#

This question thread is being automatically closed. If your question is not answered feel free to bump the post or re-ask. Take a look at !howto ask for tips on improving your question.