Dec 11, 2020 at 11:59am Dec 11, 2020 at 11:59am UTC
cout << "INSERISCI STRING1: ";
cin >> string1;
cout <<"INSERISCI STRING2: ";
cin >> string2;
if i write in this way the output is
inserisci strin1:""
inserisci string2:"
why clion put the space in the new line and not in the current line as i write?
Dec 11, 2020 at 12:29pm Dec 11, 2020 at 12:29pm UTC
I'm not sure what you're asking. Consider:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <string>
#include <iostream>
using namespace std;
int main()
{
string string1, string2;
cout << "INSERISCI STRING1: " ;
cin >> string1;
cout << "INSERISCI STRING2: " ;
cin >> string2;
}
which gives:
INSERISCI STRING1: str1
INSERISCI STRING2: str2
Note that the cin >> only completes when a <CR> is entered following text. If just a <CR> is entered then a blank line is shown but input is still required until some text has been entered followed by a <CR>.
Last edited on Dec 11, 2020 at 12:33pm Dec 11, 2020 at 12:33pm UTC
Dec 11, 2020 at 3:24pm Dec 11, 2020 at 3:24pm UTC
1 2 3 4 5 6 7 8 9
int main() {
char * ret_accoda_stringhe;
char string1[30+1],string2[30+1];
cout <<"INSERISCI STRING1: " ;
cin >> string1;
cout <<"INSERISCI STRING2: " ;
cin >> string2;
"C:\Users\Giuseppe\Desktop\SECONDO SEMESTRE\ALGORITMI&CALCOLATORI\progetti algoritmi\Esercitazioni\cmake-build-debug\Es2_2.exe"
INSERISCI STRING1:ciao
INSERISCI STRING2:mamma
the space after ':' isn't written in the output, but in the cout i write : ";
there is no space between : and ciao, but the space there is at the beginning of the new line
Last edited on Dec 11, 2020 at 3:25pm Dec 11, 2020 at 3:25pm UTC
Dec 11, 2020 at 3:31pm Dec 11, 2020 at 3:31pm UTC
Well on my Windows system, using:
1 2 3 4 5 6 7 8 9 10 11 12
include <iostream>
using namespace std;
int main() {
char string1[30 + 1], string2[30 + 1];
cout << "INSERISCI STRING1: " ;
cin >> string1;
cout << "INSERISCI STRING2: " ;
cin >> string2;
}
I get:
INSERISCI STRING1: ciac
INSERISCI STRING2: mamma
What OS are you using? What compiler/version?
It looks like there's no sync between input/output, but the input/output streams have been tied for a long time in C++.
What happens if you use:
1 2 3 4 5 6 7 8 9 10 11 12
#include <iostream>
using namespace std;
int main() {
char string1[30 + 1], string2[30 + 1];
cout << "INSERISCI STRING1: " << flush;
cin >> string1;
cout << "INSERISCI STRING2: " << flush;
cin >> string2;
}
Last edited on Dec 11, 2020 at 3:34pm Dec 11, 2020 at 3:34pm UTC
Dec 11, 2020 at 4:27pm Dec 11, 2020 at 4:27pm UTC
i use windows 10 pro, clion 2020.3
i use your code, but i have the same result :(
Dec 11, 2020 at 4:51pm Dec 11, 2020 at 4:51pm UTC
You should try a different compiler. Code::Blocks or Visual Studio are good ones that are free and work well with Windows.
Dec 11, 2020 at 5:06pm Dec 11, 2020 at 5:06pm UTC
Does your CLion use MinGW? If so, what version? You most likely can continue to use CLion as an IDE, but try to hook it up to a different compiler instead.
Last edited on Dec 11, 2020 at 5:09pm Dec 11, 2020 at 5:09pm UTC
Dec 11, 2020 at 5:21pm Dec 11, 2020 at 5:21pm UTC
Just doing a cursory search, it looks like there are some similar issues that people have faced when using MinGW-w64,
https://youtrack.jetbrains.com/issue/CPP-2580
https://youtrack.jetbrains.com/issue/CPP-11382
Apparently one of the workarounds is,
try doing the following: in Registry (Help | Find Action..., type Registry there) disable the run.processes.with.pty option and restart CLion. Does that help?
According to the response in CPP-12752 disabling PTY (without CLion restart, since the run.processes.with.pty option is not saved after CLion's restart - CPP-8395) helps.
You could also try running the program in cmd instead of whatever window CLion shows.
Last edited on Dec 11, 2020 at 5:22pm Dec 11, 2020 at 5:22pm UTC
Dec 12, 2020 at 8:19am Dec 12, 2020 at 8:19am UTC
Thanks @Ganado you got it!