我正在使用netbeans 6.8:
Product Version: NetBeans IDE 6.8 (Build 200912041610)
Java: 1.6.0_18; Java HotSpot(TM) Client VM 16.0-b13
System: Windows 7 version 6.1 running on x86; Cp1252; en_US (nb)
Userdir: C:\Users\Andre\.netbeans\6.8
我已经从我用来做C ++自学的书中复制了一个程序。这是代码:
/*
* File: main.cpp
* Author: Andre
*
* Created on December 5, 2011, 2:06 PM
*/
#include <iostream>
#include <string>
//using namespace std;
using std::cin;
using std::endl;
using std::cout;
using std::string;
int main() {
// ask for the persons name
std::string name;
cin >> name;
// build the message that we intend to write
const string greeting = "Hello, " + name + "!";
// the number of blanks surrounding the greeting
const int pad = 1;
// the number of rows and columns to write
const int rows = pad * 2 + 3;
const string::size_type cols = greeting.size() + pad * 2 + 2;
// write a blank line to separate the output from the input
cout << endl;
// write rows "rows of output"
// invariant: we have written r rows so far
for (int r = 0; r != rows; ++r) {
string::size_type c = 0;
// invariant: we have written c characters so far in the current row
while (c != cols) {
// is it time to write the greeting?
if (r == pad + 1 && c == pad + 1) {
cout << greeting.size();
} else {
// are we on the border?
if (r == 0 || r == rows - 1 || c == 0 || c == cols - 1) {
cout << "*";
} else {
cout << " ";
++c;
}
}
}
}
return 0;
}
以下是构建结果:
/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .clean-conf
make[1]: Entering directory `/d/Users/Andre/Documents/NetBeansProjects/AccCpp20'
rm -f -r build/Debug
rm -f dist/Debug/MinGW-Windows/acccpp20.exe
make[1]: Leaving directory `/d/Users/Andre/Documents/NetBeansProjects/AccCpp20'
CLEAN SUCCESSFUL (total time: 569ms)
/usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `/d/Users/Andre/Documents/NetBeansProjects/AccCpp20'
/usr/bin/make -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/acccpp20.exe
make[2]: Entering directory `/d/Users/Andre/Documents/NetBeansProjects/AccCpp20'
mkdir -p build/Debug/MinGW-Windows
rm -f build/Debug/MinGW-Windows/main.o.d
g++ -c -g -MMD -MP -MF build/Debug/MinGW-Windows/main.o.d -o build/Debug/MinGW-Windows/main.o main.cpp
mkdir -p dist/Debug/MinGW-Windows
g++ -o dist/Debug/MinGW-Windows/acccpp20 build/Debug/MinGW-Windows/main.o
make[2]: Leaving directory `/d/Users/Andre/Documents/NetBeansProjects/AccCpp20'
make[1]: Leaving directory `/d/Users/Andre/Documents/NetBeansProjects/AccCpp20'
BUILD SUCCESSFUL (total time: 1s)
当我运行程序时,我在netbeans的输出区域中显示一条消息,其中显示"Process is starting in external window..."
和一个弹出"C:\msys\1.0\bin\sh.exe
的终端窗口,只有一个空白屏幕并且闪烁光标。
当我做一个简单的程序时,只需打印"Hi!"
就可以了。这是怎么回事?
另外,如何发布代码块发布问题?教程说了4个空格...
答案 0 :(得分:2)
等待您键入您的姓名并按Enter键。此时它应继续运行。如果您希望它要求您执行此操作,则需要执行以下操作:
int main() {
// ask for the persons name
cout << "Please enter your name" << endl;
std::string name;
cin >> name;
答案 1 :(得分:1)
当你打电话给cin>>
时,程序希望用户写东西然后按回车键,然后它会继续执行,如果是这种情况输出的话。