這是我目前的C++代碼。我想知道如何寫一行代碼。我仍然會使用cin.getline(y)
還是不一樣的東西?我查過了,但找不到任何東西。 當我運行它,它完美的作品,除了它只輸入一個字,而不是我需要它輸出的完整行。這是我需要幫助的。我在代碼中概述了它。如何從用戶使用cin讀取完整的一行?
感謝您的幫助
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <fstream>
using namespace std;
int main()
{
char x;
cout << "Would you like to write to a file?" << endl;
cin >> x;
if (x == 'y' || x == 'Y')
{
char y[3000];
cout << "What would you like to write." << endl;
cin >> y;
ofstream file;
file.open("Characters.txt");
file << strlen(y) << " Characters." << endl;
file << endl;
file << y; // <-- HERE How do i write the full line instead of one word
file.close();
cout << "Done. \a" << endl;
}
else
{
cout << "K, Bye." << endl;
}
}
你可能想讓你的標題更好地反映你的問題。此外,你應該澄清你的問題,這是不是很清楚你問什麼。 – 2011-03-28 07:28:36
K done,Thanks :) – FuzionSki 2011-03-28 07:31:12
問題是'cin >> y'只存儲用戶輸入的第一個單詞,提問者想知道如何在y中存儲整行,這樣'file <
2011-03-28 07:32:20