小编use*_*851的帖子

为什么 << 运算符用 cout 截断字符?

我在 while 循环中使用 std::getline 并使用 cout 打印输出,我发现打印时我的行的开头被切断:

按预期工作:

std::string line;
while(std::getline(csv, line)) {
 std::cout << line << std::endl
}
Run Code Online (Sandbox Code Playgroud)

没有按预期工作,从我的行中删除前两个字符

std::string line;
while(std::getline(csv, line)) {
 std::cout << line << "  " << std::endl
}
Run Code Online (Sandbox Code Playgroud)

我以前从未注意到这种行为,为什么现在会发生?

c++ cout operators

5
推荐指数
1
解决办法
2459
查看次数

没有在类中声明的成员函数 - 基本编译时出错

编译基本类和标题时出现此错误.不确定我是否遗漏了明显的东西?如果需要,可以提供任何其他细节.

注意:我#include <string>在Event.h中添加了错误,但错误仍然存​​在.

Event.cpp

#include "Event.h"
#include <string>

std::string Event::getLabel() {
    return label;
}
Run Code Online (Sandbox Code Playgroud)

Event.h

#ifndef EVENT_H
#define EVENT_H

#define EVENT_STOP 0
#define EVENT_START 1


class Event {
private:

protected:
    double time;
    std::string label;
    int type; // EVENT_START OR EVENT_STOP

public:
    std::string getLabel(); 

};

#endif
Run Code Online (Sandbox Code Playgroud)

编译和错误

g++ -c -Wall -pedantic correngine.cpp
g++ -c -Wall -pedantic CSVManager.cpp
g++ -c -Wall -pedantic ServerEvent.cpp 
g++    -c -o UPSEvent.o UPSEvent.cpp
g++ -c -Wall -pedantic CorrelationEngineManager.cpp
g++ -c -Wall -pedantic Event.cpp
Event.cpp:4: error: …
Run Code Online (Sandbox Code Playgroud)

c++ compiler-errors header

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

c++ ×2

compiler-errors ×1

cout ×1

header ×1

operators ×1