當我嘗試輸出字符串時,它不輸出空格後的文本。它應該詢問學生姓名,然後在詢問時輸出。這是C++。我沒有更多的信息給,但該網站不會讓我發佈,所以這句話在這裏。打印帶空格的字符串
/***************************************************/
/* Author: Sam LaManna */
/* Course: CSC 135 Lisa Frye */
/* Assignment: Program 4 Grade Average */
/* Due Date: 10/10/11 */
/* Filename: program4.cpp */
/* Purpose: Write a program that will process */
/* students are their grades. It will */
/* also read in 10 test scores and */
/* compute their average */
/***************************************************/
#include <iostream> //Basic input/output
#include <iomanip> //Manipulators
using namespace std;
string studname(); //Function declaration for getting students name
int main()
{
string studentname = "a"; //Define Var for storing students name
studentname = studname(); //Store value from function for students name
cout << "\n" << "Student name is: " <<studentname << "\n" << "\n"; //String output test
return 0;
}
/***************************************************/
/* Name: studname */
/* Description: Get student's first and last name */
/* Paramerters: N/A */
/* Return Value: studname */
/***************************************************/
string studname()
{
string studname = "default";
cout << "Please enther the students name: ";
cin >> studname;
return studname;
}
可能的重複:http://stackoverflow.com/questions/8052009/returning-a-string(同樣的問題,不同的上下文) – IronMensan