Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/159.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;联系人文件程序 我有一个关于我在C++ Visual Studio中创建的程序的问题。首先,我想做的是从用户那里获取有关帐户输入的所有信息,然后显示给用户以确保输入正确。然后将该信息放入AccountInformation.txt文件中。到目前为止,我已经让它完成了所有的工作,它从做这个精细的cin>>Street开始,然后它会将接下来的两个cin组合在一起,所以我不知道它为什么这样做。下面是程序现在运行时的代码和示例输出 // CreateWriteDisplay.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include <fstream> #include <iostream> #include <string> #include <ostream> using std::cout; //using namespace std is not a good practice ** using std::cin; //it's best to use std:: scope or using only what you need using std::string; //not the whole namespace, C++17 allows for comma using std::endl; //separated usings using namespace std; // Declares all the variables I need. int AccountAge; string LastName; string FirstName; string Ocupation; string UserName; string EmailAdd; string HomeAddress; string TeleNum; string HomeDirectory; string RoamingProfile; string Street; string City; string State; string Zipcode; string YnRoaming; //macro definitions for max variable length #define MAX_NAME_LENGTH 50 #define MAX_ADDRESS_LENGTH 100 #define MAX_ABOUT_LENGTH 200 int main() { char name[MAX_NAME_LENGTH], address[MAX_ADDRESS_LENGTH], about[MAX_ABOUT_LENGTH]; //Gets The Accounts Personal Information: Ocupation, Full Name, Age, Email, Home Address, Telephone Number, UserName, HomeDirectory, RoamingProfile, cout << "Please enter your Ocupation: " << "\n"; getline(cin, Ocupation); cout << "Enter Your First Name and Last name: " << "\n"; cin >> FirstName >> LastName; cout << "Enter Your Age: " << "\n"; cin >> AccountAge; cout << "Please enter your Email: " << "\n"; cin >> EmailAdd; cout << "Please Enter Your Home Address( ex: 123(enter) Street( Enter), City Name(Enter), State(Enter), Zipcode(Enter)): " << "\n"; cin >> HomeAddress; cout << "Enter Street Name" << "\n"; cout << "( ex: StreetName st " << "\n"; cin >> Street; cout << "Enter City" << "\n" ; cin >> City; cout << "Enter State" << "\n"; cin >> State; cout << "Enter Zipcode" << "\n"; cin >> Zipcode; cout << "Please Enter Your Best Telephone Number(EX:508-675-4567): " << "\n"; cin >> TeleNum; cout << "Please Enter Your UserName: " << "\n"; cin >> UserName; cout << "Please Enter Your Account's HomeDirectory(EX:\\HOMEDIRECTORY\\): " << "\n"; cin >> HomeDirectory; cout << "Do you have a Roaming Profile?(Y/N)" << "\n"; cin >> YnRoaming; if (YnRoaming == "Y") { cout << "Please Enter Your Roaming Profile Name(IF APPLYS): " << "\n"; cin >> RoamingProfile; } else { string RoamingProfile = "N / A"; } //getline(cin, HomeAddress); // Displays All the information entered by the user To verify it was entered correctly. cout << "Full Name: " << LastName << "," << FirstName << ", Length: " << FirstName.length() + LastName.length() << "\n" << "Age: " << AccountAge << "\n" << "Ocupation: " << Ocupation << "\n" << "UserName: " << UserName << "\n" << "Email Address: " << EmailAdd << "\n" << FirstName << "'s Home Address" << HomeAddress << Street << City << State << Zipcode << "\n" << " Primary Telephone Number: " << TeleNum << "\n" << UserName << "'s Home Directory: " << HomeDirectory << "\n" << UserName << "'s RoamingProfile: " << RoamingProfile << "\n"; // Create File and Write to it then Close it. ofstream MyFile("AccountInformation.txt"); MyFile << "Full Name: " << LastName << "," << FirstName << ", Length: " << FirstName.length() + LastName.length() << "\n" << "Age: " << AccountAge << "\n" << "Occupation: " << Ocupation << ", Length: " << Ocupation.length() << "\n" << "UserName: " << UserName << "\n" << "Email Address: " << EmailAdd << "\n" << FirstName << "'s Home Address" << HomeAddress << "\n" << " Primary Telephone Number: " << TeleNum << "\n" << UserName << "'s Home Directory: " << HomeDirectory << "\n" << UserName << "'s RoamingProfile: " << RoamingProfile << "\n"; MyFile.close(); return 0; }_C++_Makefile_Cin - Fatal编程技术网

C++;联系人文件程序 我有一个关于我在C++ Visual Studio中创建的程序的问题。首先,我想做的是从用户那里获取有关帐户输入的所有信息,然后显示给用户以确保输入正确。然后将该信息放入AccountInformation.txt文件中。到目前为止,我已经让它完成了所有的工作,它从做这个精细的cin>>Street开始,然后它会将接下来的两个cin组合在一起,所以我不知道它为什么这样做。下面是程序现在运行时的代码和示例输出 // CreateWriteDisplay.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include <fstream> #include <iostream> #include <string> #include <ostream> using std::cout; //using namespace std is not a good practice ** using std::cin; //it's best to use std:: scope or using only what you need using std::string; //not the whole namespace, C++17 allows for comma using std::endl; //separated usings using namespace std; // Declares all the variables I need. int AccountAge; string LastName; string FirstName; string Ocupation; string UserName; string EmailAdd; string HomeAddress; string TeleNum; string HomeDirectory; string RoamingProfile; string Street; string City; string State; string Zipcode; string YnRoaming; //macro definitions for max variable length #define MAX_NAME_LENGTH 50 #define MAX_ADDRESS_LENGTH 100 #define MAX_ABOUT_LENGTH 200 int main() { char name[MAX_NAME_LENGTH], address[MAX_ADDRESS_LENGTH], about[MAX_ABOUT_LENGTH]; //Gets The Accounts Personal Information: Ocupation, Full Name, Age, Email, Home Address, Telephone Number, UserName, HomeDirectory, RoamingProfile, cout << "Please enter your Ocupation: " << "\n"; getline(cin, Ocupation); cout << "Enter Your First Name and Last name: " << "\n"; cin >> FirstName >> LastName; cout << "Enter Your Age: " << "\n"; cin >> AccountAge; cout << "Please enter your Email: " << "\n"; cin >> EmailAdd; cout << "Please Enter Your Home Address( ex: 123(enter) Street( Enter), City Name(Enter), State(Enter), Zipcode(Enter)): " << "\n"; cin >> HomeAddress; cout << "Enter Street Name" << "\n"; cout << "( ex: StreetName st " << "\n"; cin >> Street; cout << "Enter City" << "\n" ; cin >> City; cout << "Enter State" << "\n"; cin >> State; cout << "Enter Zipcode" << "\n"; cin >> Zipcode; cout << "Please Enter Your Best Telephone Number(EX:508-675-4567): " << "\n"; cin >> TeleNum; cout << "Please Enter Your UserName: " << "\n"; cin >> UserName; cout << "Please Enter Your Account's HomeDirectory(EX:\\HOMEDIRECTORY\\): " << "\n"; cin >> HomeDirectory; cout << "Do you have a Roaming Profile?(Y/N)" << "\n"; cin >> YnRoaming; if (YnRoaming == "Y") { cout << "Please Enter Your Roaming Profile Name(IF APPLYS): " << "\n"; cin >> RoamingProfile; } else { string RoamingProfile = "N / A"; } //getline(cin, HomeAddress); // Displays All the information entered by the user To verify it was entered correctly. cout << "Full Name: " << LastName << "," << FirstName << ", Length: " << FirstName.length() + LastName.length() << "\n" << "Age: " << AccountAge << "\n" << "Ocupation: " << Ocupation << "\n" << "UserName: " << UserName << "\n" << "Email Address: " << EmailAdd << "\n" << FirstName << "'s Home Address" << HomeAddress << Street << City << State << Zipcode << "\n" << " Primary Telephone Number: " << TeleNum << "\n" << UserName << "'s Home Directory: " << HomeDirectory << "\n" << UserName << "'s RoamingProfile: " << RoamingProfile << "\n"; // Create File and Write to it then Close it. ofstream MyFile("AccountInformation.txt"); MyFile << "Full Name: " << LastName << "," << FirstName << ", Length: " << FirstName.length() + LastName.length() << "\n" << "Age: " << AccountAge << "\n" << "Occupation: " << Ocupation << ", Length: " << Ocupation.length() << "\n" << "UserName: " << UserName << "\n" << "Email Address: " << EmailAdd << "\n" << FirstName << "'s Home Address" << HomeAddress << "\n" << " Primary Telephone Number: " << TeleNum << "\n" << UserName << "'s Home Directory: " << HomeDirectory << "\n" << UserName << "'s RoamingProfile: " << RoamingProfile << "\n"; MyFile.close(); return 0; }

C++;联系人文件程序 我有一个关于我在C++ Visual Studio中创建的程序的问题。首先,我想做的是从用户那里获取有关帐户输入的所有信息,然后显示给用户以确保输入正确。然后将该信息放入AccountInformation.txt文件中。到目前为止,我已经让它完成了所有的工作,它从做这个精细的cin>>Street开始,然后它会将接下来的两个cin组合在一起,所以我不知道它为什么这样做。下面是程序现在运行时的代码和示例输出 // CreateWriteDisplay.cpp : This file contains the 'main' function. Program execution begins and ends there. // #include <fstream> #include <iostream> #include <string> #include <ostream> using std::cout; //using namespace std is not a good practice ** using std::cin; //it's best to use std:: scope or using only what you need using std::string; //not the whole namespace, C++17 allows for comma using std::endl; //separated usings using namespace std; // Declares all the variables I need. int AccountAge; string LastName; string FirstName; string Ocupation; string UserName; string EmailAdd; string HomeAddress; string TeleNum; string HomeDirectory; string RoamingProfile; string Street; string City; string State; string Zipcode; string YnRoaming; //macro definitions for max variable length #define MAX_NAME_LENGTH 50 #define MAX_ADDRESS_LENGTH 100 #define MAX_ABOUT_LENGTH 200 int main() { char name[MAX_NAME_LENGTH], address[MAX_ADDRESS_LENGTH], about[MAX_ABOUT_LENGTH]; //Gets The Accounts Personal Information: Ocupation, Full Name, Age, Email, Home Address, Telephone Number, UserName, HomeDirectory, RoamingProfile, cout << "Please enter your Ocupation: " << "\n"; getline(cin, Ocupation); cout << "Enter Your First Name and Last name: " << "\n"; cin >> FirstName >> LastName; cout << "Enter Your Age: " << "\n"; cin >> AccountAge; cout << "Please enter your Email: " << "\n"; cin >> EmailAdd; cout << "Please Enter Your Home Address( ex: 123(enter) Street( Enter), City Name(Enter), State(Enter), Zipcode(Enter)): " << "\n"; cin >> HomeAddress; cout << "Enter Street Name" << "\n"; cout << "( ex: StreetName st " << "\n"; cin >> Street; cout << "Enter City" << "\n" ; cin >> City; cout << "Enter State" << "\n"; cin >> State; cout << "Enter Zipcode" << "\n"; cin >> Zipcode; cout << "Please Enter Your Best Telephone Number(EX:508-675-4567): " << "\n"; cin >> TeleNum; cout << "Please Enter Your UserName: " << "\n"; cin >> UserName; cout << "Please Enter Your Account's HomeDirectory(EX:\\HOMEDIRECTORY\\): " << "\n"; cin >> HomeDirectory; cout << "Do you have a Roaming Profile?(Y/N)" << "\n"; cin >> YnRoaming; if (YnRoaming == "Y") { cout << "Please Enter Your Roaming Profile Name(IF APPLYS): " << "\n"; cin >> RoamingProfile; } else { string RoamingProfile = "N / A"; } //getline(cin, HomeAddress); // Displays All the information entered by the user To verify it was entered correctly. cout << "Full Name: " << LastName << "," << FirstName << ", Length: " << FirstName.length() + LastName.length() << "\n" << "Age: " << AccountAge << "\n" << "Ocupation: " << Ocupation << "\n" << "UserName: " << UserName << "\n" << "Email Address: " << EmailAdd << "\n" << FirstName << "'s Home Address" << HomeAddress << Street << City << State << Zipcode << "\n" << " Primary Telephone Number: " << TeleNum << "\n" << UserName << "'s Home Directory: " << HomeDirectory << "\n" << UserName << "'s RoamingProfile: " << RoamingProfile << "\n"; // Create File and Write to it then Close it. ofstream MyFile("AccountInformation.txt"); MyFile << "Full Name: " << LastName << "," << FirstName << ", Length: " << FirstName.length() + LastName.length() << "\n" << "Age: " << AccountAge << "\n" << "Occupation: " << Ocupation << ", Length: " << Ocupation.length() << "\n" << "UserName: " << UserName << "\n" << "Email Address: " << EmailAdd << "\n" << FirstName << "'s Home Address" << HomeAddress << "\n" << " Primary Telephone Number: " << TeleNum << "\n" << UserName << "'s Home Directory: " << HomeDirectory << "\n" << UserName << "'s RoamingProfile: " << RoamingProfile << "\n"; MyFile.close(); return 0; },c++,makefile,cin,C++,Makefile,Cin,您需要更改cin>>EmailAdd下面的行将cin.ignore()然后放入getline(cin,家庭地址)这将获取整个地址,并像我所希望的那样将其全部存储在变量HomeAddress中。我还实施了一些更改,使其运行更顺畅 cin将其输入拆分为空白,如果您给它多个单词作为输入,以下单词将传递给以后的cin语句。根据你的描述,我打赌你正在传递一个带有空格的街道名称。如果要在输入中保留空白,则需要使用getline。@0x5453更准确地说,是operator>在空白上拆分,而不是std::ci

您需要更改
cin>>EmailAdd下面的行
cin.ignore()然后放入
getline(cin,家庭地址)
这将获取整个地址,并像我所希望的那样将其全部存储在变量HomeAddress中。我还实施了一些更改,使其运行更顺畅

cin
将其输入拆分为空白,如果您给它多个单词作为输入,以下单词将传递给以后的
cin
语句。根据你的描述,我打赌你正在传递一个带有空格的街道名称。如果要在输入中保留空白,则需要使用
getline
。@0x5453更准确地说,是
operator>
在空白上拆分,而不是
std::cin
本身。您可以使用
std::cin.get()
std::cin.getline()
std::getline()
std::cin
(或任何
std::istream
)读取多字字符串。哦,好的,谢谢您的建议。但是我让我的程序开始工作,问题是cini在缓冲区中留下了一个新行字符,因此getline函数将其吃掉,并且它似乎跳过了getline cin,因此需要使用cin.ignore();但是谢谢你是什么让你写了
//声明了我需要的所有变量。
你不是这么做的吗?
Please enter your Ocupation:
Citizens For Citizens
Enter Your First Name and Last name:
Mark Monhan
Enter Your Age:
24
Please enter your Email:
mmonhan23@gmail.com
Please Enter Your Home Address( ex: 123(enter) Street( Enter), City Name(Enter), State(Enter), Zipcode(Enter)):
524
Enter Street Name
( ex: StreetName st
Street st
Enter City
Enter State
Boston MA
Enter Zipcode
Please Enter Your Best Telephone Number(EX:508-675-4567):
02726 603-854-7845
Please Enter Your UserName:
Please Enter Your Account's HomeDirectory(EX:\HOMEDIRECTORY\):
mgede
Do you have a Roaming Profile?(Y/N)
N
Full Name: Monhan,Mark, Length: 10
Age: 24
Ocupation: Citizens For Citizens
UserName: 603-854-7845
Email Address: mmonhan23@gmail.com
Mark's Home Address524StreetstBostonMA
 Primary Telephone Number: 02726
603-854-7845's Home Directory: mgede
603-854-7845's RoamingProfile:
``` ***