I have just started work on asmall program that sends text over net (TON) I havent quite started but when I compile this happens when I have a space in my name
Username: Knight Hawk3
LAN (1) or Net (0):
(Here it wont let me enter data)
Process returned 1 (0x1) execution time : 3.670 s
Press any key to continue.
Here is what normally (should) happen
Username: Knight
LAN (1) or Net (0):
1
Process returned 1 (0x1) execution time : 2.134 s
Press any key to continue.
Here is my source
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Network.hpp>
#include <iostream>
#include <string>
using namespace std;
bool firstrun = true;
int main() {
if (firstrun) {
cout << "Username: ";
string name = "";
cin >> name;
while (name == "") {
cout << "Invalid Enter a new name: ";
cin >> name;
cout << "\n";
}
}
cout << "LAN (1) or Net (0): ";
int type;
cout << "\n";
cin >> type;
while (type < 0) {
cout << "Invalid LAN (1) or Net (0): ";
cin >> type;
}
return true;
}
I am running WIN7, Using Code::Blocks
Why is this happening with a space?
std::cinreads till the first space but keeps the rest in buffer, which will be used on the followingstd::cins.If you want to read till the first
'\n'(hitting enter) you have to replacestd::cinwith