account admin; ifstream ifile("D:\\admin.txt"); string id; string pas; if (getline(ifile>>ws, id)) { if (getline(ifile>>ws, pas)) { admin.id = id; admin.password = pas; } } ifile.close(); string tmi; cout << admin.id << endl; cout << "wrong" << endl; string tmp; system("cls"); cout << "ID:" << ends; cin >> tmi; if (tmi == admin.id) { cout << "Password:" << ends; cin >> tmp; if (tmp == admin.password) { cout << " ___________________________________________________________________________________" << endl; cout << "| |" << endl; cout << "| Welcom,admin. | " << endl; cout << "| |" << endl; cout << "|___________________________________________________________________________________|" << endl; system("cls"); } }这段代码里cout<<admin.id这条语句被忽略无法执行是为什么
时间: 2024-02-16 17:26:46 浏览: 27
根据代码,文件中的管理员账户信息已经被读入到了`admin`对象中,所以`cout << admin.id`语句应该能够输出管理员账户的ID。但是,在这段代码中,`cout << admin.id`语句和后面的`cout << "wrong" << endl`语句之间没有添加换行符,所以这两个语句的输出结果会连在一起,导致输出结果不易观察。可以将这两个语句分别改为`cout << admin.id << endl`和`cout << "wrong" << endl`,然后再次运行程序,看是否能够输出管理员账户的ID。
相关问题
如何解决c++中[Error] no matching function for call to 'std::basic_ifstream<char>::basic_ifstream(std::str...
这个错误通常表示在调用 `std::ifstream` 构造函数时,传入的参数类型不匹配。要解决这个问题,你需要检查你在调用构造函数时传入的参数类型是否正确。
比如,如果你使用了以下代码:
```c++
std::ifstream file("example.txt");
```
但是 `example.txt` 文件不存在,那么就会出现该错误。此时,你需要检查文件路径是否正确,或者确认文件是否存在。
另外,如果你在调用构造函数时传入的不是一个字符串类型,也会出现该错误。例如,如果你使用了以下代码:
```c++
std::ifstream file(42);
```
那么编译器就会报错,因为 42 不是一个字符串类型。此时,你需要将文件路径传入构造函数,例如:
```c++
std::ifstream file("example.txt");
```
总之,要解决这个错误,你需要仔细检查传入构造函数的参数类型是否正确,以及文件路径是否存在。
怎么解决[Error] no matching function for call to 'std::basic_ifstream<char>::basic_ifstream(std::string&...
这个错误通常是因为在使用 `std::ifstream` 时,传入的参数类型与构造函数所期望的参数类型不匹配导致的。可以尝试以下两种解决方法:
1. 将参数类型转换为构造函数所期望的类型。比如,如果构造函数期望传入 `const char*` 类型的文件名,而你传入的是 `std::string` 类型,可以将其转换为 `const char*` 类型,如下所示:
```cpp
std::string filename = "example.txt";
std::ifstream file(filename.c_str());
```
2. 使用 `std::ifstream` 的另一种构造函数,该构造函数接受一个 `std::string` 类型的参数。如下所示:
```cpp
std::string filename = "example.txt";
std::ifstream file;
file.open(filename);
```
这两种方法都可以解决这个错误。如果还有问题,请让我知道。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)