似乎无法通过线路读取TMP文件
Cant seem to read a tmp file via ifstream line by line
喜欢知道我在做什么错。我有一个文件(file.tmp(,其内容为:c: users documents file file folder folder myfile.txt。我想使用此代码读取TMP文件:
std::ifstream istream(csTempPath);
std::string s;
if (istream.is_open()){
int i = 1;
while (std::getline(istream, s))
{
CString cs;
cs.Format(L"Reading: %s", s);
OutputDebugString(cs);
i++;
}
istream.close();
}
else{
OutputDebugString(L"Could not read the temp file.");
}
输出即时通讯是:
[4376] Reading: ??
[4376] Reading: ??
我希望它能得到:c:usersdocumentsfilefoldermyfile.txt
,但是由于某种原因,我尝试了多种方法,但我似乎不知道怎么了。顺便说一句,我是一个开始程序员。
%s
格式指定器期望 const char*
(或 const wchar_t*
,取决于您的字符编码设置(,但您正在传递 std::string
对象。您需要调用其C_ST成员:
CStringA cs;
cs.Format("Reading: %s", s.c_str());
OutputDebugStringA(cs);
或使用Unicode字符编码(似乎是(:
CStringW cs;
cs.Format(L"Reading: %S", s.c_str());
OutputDebugStringW(cs);
请注意,后者使用Microsoft特定的扩展名,即格式指定类型%S
,该扩展程序执行了字符编码ANSI编码和Unicode之间的转换。
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- 使用新行和不使用新行读取文件
- 读取文件并输入到矢量中
- 用c++从输入文件中读取另一行
- 读取文件的最后一行并输入到链接列表时出错
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 无法找到/读取配置文件.conf-FileIOException
- 如何使用Luacneneneba API正确读取字符串和表参数
- C++将文本文件中的数据读取到结构数组中
- 正在将csv文件读取为双精度矢量
- 为什么 sscanf 无法从一个字符串中读取uint64_t和字符?
- 为什么在读取文件大小时文件IO速度会发生变化
- 正在读取二进制文件(is_open)
- 如何在c++中从文本文件中逐行读取整数
- SSH通过/sbin/SSH无法读取RSA密钥文件(从控制台运行)
- 独立读取-修改-写入顺序
- 从文本文件中读取时钟时间和事件时间并进行处理
- 如何从文本文件中读取值和数组
- 似乎无法通过线路读取TMP文件
- 从C 中的线路读取(每行都有一个字符串和几个INT值)