-1
/*
* hello_world.cpp
*
* Created on: Feb 21, 2017
* Author: George Lutas
*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
inline void keep_window_open() { char ch; cin>>ch; }
int main() //C++ programs start by executing the function main
{
cout << "George 17\n";
string first_name = "George";
int age = 17;
cin >> first_name >> age;
cout << "Hello," << first_name << "(age" << age << ")" << endl;
}
這是我的代碼。我在這裏錯過了什麼。代碼的目標是輸出「你好,喬治(17歲)」。那麼,我怎樣才能讀懂它,而不是「George 17」?另外,我知道我沒有安裝std_lib_facilities.h。這是有意的。我很確定(事實上沒有錯誤出現),我有我需要加載的庫。C++代碼cout打印而不是等待它在字符串中使用
''''cin'''沒有附加到''''cout'''''。你基本上寫出了「喬治17」終端,然後在鍵盤輸入阻塞。 – mascoj
@mascoj擴展:至少使用'<< std :: flush'來強制輸出到終端。 –
@πάνταῥεῖ - 不,不需要'std :: flush'。 'std :: cin'和'std :: cout'是綁定的,因此在'std :: cin'上調用一個流提取器將刷新'std :: cout'。 –