C++ std:getline.....

Discussion about hacker.org's server
Post Reply
Liidian
Posts: 202
Joined: Fri Jun 05, 2009 10:49 pm
Location: Guess

C++ std:getline.....

Post by Liidian »

Why doesn't

string x;
std::getline(cin, x)

Do anything? It basically just jumps this line without doing anything at all. I don't understand why, is this outdated or something?
The whole "system" is a number of people creating a code all together, this code loops and is there for a "system".
System Zero could also be confirmed with one word "Hacker's"
AMindForeverVoyaging
Forum Admin
Posts: 496
Joined: Sat May 28, 2011 9:14 am
Location: Germany

Post by AMindForeverVoyaging »

This here works for me:

Code: Select all

#include <iostream>
using std::cin;
using std::string;

int main()
{
	string x;
	std::getline(cin, x);
	
	std::cout << "You entered: " << x << std::endl;
	
	return 0;
}
Liidian
Posts: 202
Joined: Fri Jun 05, 2009 10:49 pm
Location: Guess

Post by Liidian »

AMindForeverVoyaging wrote:This here works for me:

Code: Select all

#include <iostream>
using std::cin;
using std::string;

int main()
{
	string x;
	std::getline(cin, x);
	
	std::cout << "You entered: " << x << std::endl;
	
	return 0;
}
Basically im making a school project for the end term, and i figured ill make a program which does what you tell it to do. So i started exeprimenting with some raw code to see if i could get to the point i wanted. This for i got stuck in the main function since following code does not work for me!!

Code: Select all

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

int main()

{
    std::string name;
    string b;
    int x;
    
    cout << "Welcome please enter the password code." << endl;
    cin >> x;
    
    
        if(x==7777){
        

    system("pause");
    
    cout << "What is your name?" << endl;
    cin >> b;
    
    
    cout << "Hello " << b << " what do you want to do today?" << endl;
    std::getline(cin, name);
    
    std::cout << name << endl;
    system("pause");
}
                    else{
                         cout << "Wrong Code" << endl << "press enter to close to application" << endl;
                         system("pause");
                         
}
return 0;
}
I know very well how badly this is written. I am only trying to get things to work so can write the actual program but id on't know why it jumps the fuction, and others usually spot you mistakes easier! :D
thanks for help.
The whole "system" is a number of people creating a code all together, this code loops and is there for a "system".
System Zero could also be confirmed with one word "Hacker's"
Post Reply