Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.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++ 将TXT行读入字符_C++ - Fatal编程技术网

C++ 将TXT行读入字符

C++ 将TXT行读入字符,c++,C++,我现在完全没有主意了。基本上,我想读取文本文件中的部分行,但这段代码不起作用,我不知道为什么: char temp_char = '\0'; char _char = '\0'; while(1) { _places.get(temp_char); if(temp_char == '\t') break; _char += t

我现在完全没有主意了。基本上,我想读取文本文件中的部分行,但这段代码不起作用,我不知道为什么:

        char temp_char  = '\0';
        char _char = '\0';
        while(1)
        {
            _places.get(temp_char);
            if(temp_char == '\t')
                break;

            _char += temp_char;

            cout << _char;
        }
chartemp_char='\0';
char _char='\0';
而(1)
{
_places.get(临时字符);
如果(临时字符='\t')
打破
_字符+=临时字符;
cout>

我已经做了一个小时的实验,浏览了很多网站寻求帮助,但我一无所获……所有这些都让我感到压力很大

编辑:如果这不是问题,我也可以提供其余的程序代码,但应该是:/

以下是打开文件的位置:

                ifstream _places;
                _places.open("ECC.txt");
                if (_places.fail())
                {
                    cout << "Could not load text file, please make sure ECC.txt is in the same folder.";
                    _getch();
                    exit(1);
                }
ifstream\u位置;
_places.open(“ECC.txt”);
if(_places.fail())
{

首先,char是std::string、char[]还是char*

第二,我会用这两种方法

temp_char = _places.get()

std::字符串温度;
getline(_位置,温度)

对于(unsigned int i=0;i为什么要在_字符上做一个“+=”,这是一个std::string吗?放在什么地方?你能把代码放在打开文件的地方吗?流还可以吗?欢迎使用堆栈溢出。我们不想看到程序的其余部分。我们想看到一个复制错误的小程序的其余部分。有关提示,请参阅。你可以说文本文件“是正确的编码”“你认为哪一个是正确的?你使用什么编码?你在编译哪个平台?”Codi-Gray我用VisualStudioC++ 2010对我试图打开的文件编译和ANSI编码。@ KavaSa:这样的信息是在问题中,而不是评论。评论可以被删除,没有警告。正在将_char用作char,但似乎工作不正常。将_char切换为字符串并切换:_places.get(temp_char);with temp_char=_places.get()工作得很好。不过,我之所以使用_char作为char,是为了能够将其转换为int。正如您所知,char只是一个字符。说char c=char+char毫无意义。如果您想将其转换为int,可以使用atoi()获取int值(使“4”变为4)或仅使用int(char)用于获取ASCII值。您的问题解决了吗?或者还有其他问题吗?如果解决了,请编辑您的问题:)事实上,这回答了我的问题,谢谢!我想我现在已经有足够的时间完成我的项目了^_^
std::string temp;
getline(_places,temp)
for (unsigned int i=0; i<temp.size(), ++i)
    if (temp[i] == '\t')
        break;
    _char += temp[i] // assuming, and REALLY HOPING _char is a std::string